C#,Winform关闭登入窗口打开主窗口的方法

相关的视频教程 https://www.bilibili.com/video/BV1Sw411R7HX

Program.cs中代码:

static class Program
{
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Form1 form1 = new Form1();
        if (form1.ShowDialog() == DialogResult.OK)
        {
            Application.Run(new Form2());
        }
      
    }
}


在登录窗体(Form1)中代码:

private void button1_Click(object sender, EventArgs e)
{
    if (txtUserName.Text == "123" && txtUsePwd.Text == "123")
    {
        this.DialogResult = DialogResult.OK;
    }
    else
    {
        MessageBox.Show("帐号或密码错误 ");
    }
}


评论