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

  • 相关阅读:
    【转】谈谈 JVM 内部锁升级过程
    TCP 和 UDP 协议简介
    《分布式系统原理介绍》读书笔记
    Paxos 协议简单介绍
    Lease 机制和 Quorum 机制
    HBase 学习二(最佳实践).
    HBase 学习一(基础入门).
    Spring 事务介绍
    《MySQL技术内幕:InnoDB存储引擎》读书笔记.
    数据库事务简介.
  • 原文地址:https://www.cnblogs.com/omme/p/10114541.html
Copyright © 2011-2022 走看看