刚给你随便写了个,我按你的意思理解写了2个窗体,一个Logon窗体,一个登录成功后看见的Welcom窗体。 当Logon登录成功后就可以看见Welcom窗体并且Logon窗体“消失”了。下面看代码; Logon窗体的代码:using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace LogonForm { public partial class LogonForm : Form { WelcomForm _welcomeForm; public LogonForm() { _welcomeForm = new WelcomForm(); InitializeComponent(); } private void btnLogon_Click(object sender, EventArgs e) { if (txtUserName.Text == "admin" && txtPwd.Text == "test")//随便写了个用户名和密码 { _welcomeForm.Show();//用户名,密码验证通过时显示Welcom窗体 this.Hide(); 并且隐藏自身,就是你所说的登录页面自动消失 } else { MessageBox.Show("输入的用户名,密码是否正确?","登录失败"); } } private void btnCancel_Click(object sender, EventArgs e) { Application.Exit(); } } } 下面是Welcom窗体的代码:using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace LogonForm { public partial class WelcomForm : Form {
当Logon登录成功后就可以看见Welcom窗体并且Logon窗体“消失”了。下面看代码;
Logon窗体的代码:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace LogonForm
{
public partial class LogonForm : Form
{
WelcomForm _welcomeForm;
public LogonForm()
{
_welcomeForm = new WelcomForm();
InitializeComponent();
} private void btnLogon_Click(object sender, EventArgs e)
{
if (txtUserName.Text == "admin" && txtPwd.Text == "test")//随便写了个用户名和密码
{
_welcomeForm.Show();//用户名,密码验证通过时显示Welcom窗体
this.Hide(); 并且隐藏自身,就是你所说的登录页面自动消失
}
else
{
MessageBox.Show("输入的用户名,密码是否正确?","登录失败");
}
} private void btnCancel_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
下面是Welcom窗体的代码:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace LogonForm
{
public partial class WelcomForm : Form
{
public WelcomForm()
{
InitializeComponent();
} private void btnClose_Click(object sender, EventArgs e)
{
this.Close();//Welcom页面上的一个退出Button
}
}
}
假设你有2个Form,一个Form1,一个Form2
你在Form1中拖个button,在button_Click事件下实例化一下Form2就可以了Form2 form2 = new Form(); //实例化Form2
form2.Show(); // 把对象form2给Show出来就可以了this.Hide(); //同时把自身给隐藏了