三个窗口:loginform,mainform,regform
在Program.cs中要设置loginform为运行窗口:
Application.Run(new loginForm()); //如果有就不用改,没有就改正
loginform中,进主窗口的按钮代码:
private void button1_Click(object sender, EventArgs e)
{
mainForm f = new mainForm();
f.Show();
Hide();
}
loginform中,进注册窗口的按钮代码:
private void button2_Click(object sender, EventArgs e)
{
regForm f = new regForm();
f.Show();
Hide();
}
mainform的窗口关闭代码:
private void mainForm_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
regform的窗口关闭代码
private void regForm_FormClosed(object sender, FormClosedEventArgs e)
{
mainForm f = new mainForm();
f.Show();
}
-----------------------------------------------------------------
ok,实现
static class Program
{
///
/// 应用程序的主入口点。
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 f1 = new Form1();
f1.ShowDialog();
if (f1.DialogResult == DialogResult.OK)
{
Application.Run(new Form2());
}
}
}
main函数
————————————————————
登录窗体
private void button1_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
}