我现在的是登陆窗口登陆成功之后才显示主窗口。。
private void Form1_Load(object sender, EventArgs e)
{
loginForm lf = new loginForm();
bool logined = false;
do
{
if (lf.ShowDialog(this) == DialogResult.OK)
{
string u = "u";
string p = "p";
if (lf.UserName == u && lf.UserPwd == p)
{
logined = true;
lf.Close();
}
else
{
MessageBox.Show("非法登陆", "管理员登陆", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
} }
else
{
this.Close();
}
}
while (!logined && (lf.DialogResult == DialogResult.OK)); }
在loginform里面这样写
protected internal void button1_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
} private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
public string UserName
{
get { return this.textBox1.Text; }
}
public string UserPwd
{
get { return this.textBox2.Text; }
}
private void Form1_Load(object sender, EventArgs e)
{
loginForm lf = new loginForm();
bool logined = false;
do
{
if (lf.ShowDialog(this) == DialogResult.OK)
{
string u = "u";
string p = "p";
if (lf.UserName == u && lf.UserPwd == p)
{
logined = true;
lf.Close();
}
else
{
MessageBox.Show("非法登陆", "管理员登陆", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
} }
else
{
this.Close();
}
}
while (!logined && (lf.DialogResult == DialogResult.OK)); }
在loginform里面这样写
protected internal void button1_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
} private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
public string UserName
{
get { return this.textBox1.Text; }
}
public string UserPwd
{
get { return this.textBox2.Text; }
}
{
this.Show();
using (Form2 frm = new Form2())
{
frm.ShowDialog(this);
}
}主要是,在你登录窗口出现之前,调用一下,this.Show();
可以试着在Load函数里家一个Timer然后设timer的时间为100毫秒,到时间了之后显示登陆窗口,试试。
using用的好,出了这一段,就直接销毁掉。结贴给分
{
Form1 f1=new Form1();
f1.Show();
Form2 f2=new Form2();
f2.ShowDialog();
//Application.Run(new Form1());
}