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

  • 相关阅读:
    Java低配版简单的随机点名系统
    是否二叉搜索树
    输出学生成绩
    求给定精度的简单交错序列部分和
    字符串的连接
    学生信息链表,建立,插入,删除,遍历,查找,修改,最大(小)值,平均
    测试文档(final)
    详细设计文档(final)
    概要设计文档(final)
    需求规格说明书(final)
  • 原文地址:https://www.cnblogs.com/omme/p/10114541.html
Copyright © 2011-2022 走看看