private void btnOK_Click(object sender, System.EventArgs e)
{
Form MainForm=new MainForm(this.txtUser.Text,"system");
MainForm.ShowDialog();
this.Close();
}此函数的作用是: 用户登录界面的,当用户输入用户名,密码后进入主Form, 同时关闭登录的Form, 可是我这里this.Close();却关闭不了,为什么不能关闭?我用VS.net(C#) 开发.
{
Form MainForm=new MainForm(this.txtUser.Text,"system");
MainForm.ShowDialog();
this.Close();
}此函数的作用是: 用户登录界面的,当用户输入用户名,密码后进入主Form, 同时关闭登录的Form, 可是我这里this.Close();却关闭不了,为什么不能关闭?我用VS.net(C#) 开发.
会把当前函数阻塞,你的this.Close();就执行不了。你如果关了你的MainForm,这个登录界面马上就可以关了。对不对?
你最好改成:
Form MainForm=new MainForm(this.txtUser.Text,"system");
this.Hide();
MainForm.ShowDialog();
所以要么用hide隱藏登录窗體,要么將ShowDialog()改為Show();
private void btnOK_Click(object sender, System.EventArgs e)
{
Form MainForm=new MainForm(this.txtUser.Text,"system");
MainForm.Show();
this.Close();
}
frmMain m = new frmMain();
m.Show();
this.Close() ;
this.Hide();
MainForm frm=new MainForm();
frm.ShowDialog();
frm.Dispose();
用这里试下,应该没错,我的是这样的
public class MainClass
{
public static Form myform=null;
public MainClass()
{
//
// TODO: ヤレエヒエヲフ晴モケケヤ・ッハツ゚シュ
//
}
/// <summary>
/// モヲモテウフミトヨ・レオ
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new login ());
if (myform!=null)
{
Application.Run(myform); }
}
}
在loinform 里:
MainClass.myform =new mainForm ();
this.Close ();