zoukankan      html  css  js  c++  java
  • 关闭主进程和弹出唯一窗体

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication8
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                if (textBox1.Text == "feng" && textBox2.Text == "123")
                {
                    Form2 f2 = new Form2(this);
                    f2.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("输入有误!");
                    return;
                }
            }
        }
    }

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication8
    {
        public partial class Form2 : Form
        {
            Form1 F1;
            public Form2(Form1 f1)//窗体传值
            {
                InitializeComponent();
                F1 = f1;
            }
    
            private void Form2_FormClosed(object sender, FormClosedEventArgs e)
            {
                F1.Close();//当form2关闭的时候,form1同时关闭
            }
            List<Form> list = new List<Form>();
            private void button1_Click(object sender, EventArgs e)
            {
                bool has = false;
                Form3 f3 = new Form3(this);
                f3.Owner = this;
                
                foreach(Form f in list)
                {
                    if (f.Name == f3.Name)//判断一下是否有该窗体
                    {
                        has = true;//如果有该窗体,记录一下
                        f.WindowState = FormWindowState.Normal;//窗体启动常规大小
                        f.Show();//已有的窗体显示
                        f3.Close();//新建的窗体关闭
                        f.Activate();//激活窗体并赋给它窗体
                    }
                }
    
                if (has == false)//如果没有该窗体
                {
                    f3.Show();//创建显示一个form3的窗体
                    list.Add(f3);//添加form3窗体进入list集合中
                }
            }
            //当form3窗体关闭后,将form3窗体从list集合中移除
            public void deleteform3( Form3 f3)
            {
                List<Form> aa=new List<Form>();
                foreach(Form f in list )
                {
                    if(f.Name!=f3.Name)
                    {
                        aa.Add(f);
                    }
    
                }
                list=aa;
            }
    
    
    
    
        }
    }

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication8
    {
        public partial class Form3 : Form
        {
            Form2 F2;
            public Form3(Form2 f2)
            {
                InitializeComponent();
                F2 = f2;
                
            }
    
            private void Form3_FormClosing(object sender, FormClosingEventArgs e)
            {
                F2.deleteform3(this);//移除form3窗体
            }
        }
    }

  • 相关阅读:
    第3章 管道符、重定向与环境变量
    基于Linux命令行KVM虚拟机的安装配置与基本使用
    Linux系统真正的优势以及学习方法
    一款在线编写接口文档的工具
    springboot前端传参date类型后台处理方式
    软件工程专业需要知道的缩写和专业名词
    七牛云图床及MPIC工具使用
    阿里云ECS云服务器CentOS部署个人网站
    【字】biang
    【车】打开车窗技巧
  • 原文地址:https://www.cnblogs.com/fengsantianya/p/5638634.html
Copyright © 2011-2022 走看看