c# 如何判断当前窗体是否打开

using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{    
    public partial class Form1 : Form
    {
        public static string username;
        public Form2 form2 = null; //定义窗体
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            username = "123456";
            MessageBox.Show(username);

            if (form2 == null) //判断窗体是否存在
            {
                form2 = new Form2();
                form2.Show();
                this.Hide();
            }



        }
    }

}

 

    原文作者:天锋
    原文地址: https://blog.csdn.net/yugui/article/details/109395827
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞