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

  • 相关阅读:
    老友记实战,17上
    老友记实战,9下
    老友记实战,5下
    公共样式base.css
    单选框radio总结(获取值、设置默认选中值、样式)
    js tab切换
    HTTP状态码100、200、300、400、500、600的含义
    微信小程序事件绑定
    微信小程序获取手机验证码
    js滚动到指定位置导航栏固定顶部
  • 原文地址:https://www.cnblogs.com/omme/p/10114541.html
Copyright © 2011-2022 走看看