zoukankan      html  css  js  c++  java
  • c#多个窗体时,点击按钮,一次关闭所有窗体

    class1.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace WindowsFormsApplication3
    {
    public static class Class1
    {
    public static Form1 bridegeOfForm1;//为什么这个字段的类型是form1呢?主窗体!
    }
    }


    program.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace WindowsFormsApplication3
    {
    static class Program
    {
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main()
    {
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());//有这行代码可以看出,form1是主窗体
    }
    }
    }


    Form1.cs

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace WindowsFormsApplication3
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
    Class1.bridegeOfForm1 = this;
    }

    private void button1_Click(object sender, EventArgs e)
    {
    Form2 frm2 = new Form2();
    frm2.Show();
    }
    }
    }

    form2.cs
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace WindowsFormsApplication3
    {
    public partial class Form2 : Form
    {
    public Form2()
    {
    InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
    Class1.bridegeOfForm1.Close();
    }
    }
    }
    ---------------------
    作者:心少朴
    来源:CSDN
    原文:https://blog.csdn.net/yushaopu/article/details/52561522

  • 相关阅读:
    GridView的简单使用
    获取当前应用程序的版本号
    Android EditText输入光标居于开头最开始位置
    Linux-开机启动程序-chkconfig
    Linux-显示行号-方案
    Linux-命令-cat
    Linux-测试-第二关
    Linux-正则-Reg
    Linux-测试-第一关
    Linux-命令-uname
  • 原文地址:https://www.cnblogs.com/omme/p/10114541.html
Copyright © 2011-2022 走看看