开发者

Window form does not close

Hey guys i am new to the Windows application.

I have a form on which Login button click event i have shown to other Forms. Example like i have a login page after user authentication other two Forms shown. But i want after authentication of user Login Form should be close, But others two remain open.

Following is code, my Login Form name is LogIn.cs

private void btnLogIn_Click(object sender, EventArgs e)
{
    if(ValidateUser())
    {
       //Form1

        DetailForm form = new DetailForm(txtUserName.Text.ToString());
        form.Show();

        //Form2

        Progressbar progress = new Progressbar();
        progress.Show();
    }
}

开发者_JAVA百科please write some code


You can close the form using Form.Close()


private void btnLogIn_Click(object sender, EventArgs e)
{
    if(ValidateUser())
    {
       //Form1

        DetailForm form = new DetailForm(txtUserName.Text.ToString());
        form.Show();

        //Form2

        Progressbar progress = new Progressbar();
        progress.Show();
        this.Close();
    }
}


There is a "Close" method on every form you can use.


The problem is that the Main message loop of your application is in the LogIn form, it means that if you stop this message loop, your application stops.
Personally I won't let the LogIn form own the main message loop of your app. I wouldn't open the DetailForm and the ProgressBar from the LogIn form, it doesn't make much sense. I'd make some parent class which controls all of them.
If you do want the LogIn form to be the main of your app but hide it once the user logs in, you could either use Hide(), or run the two child windows in seperate Threads or Processes (not Highly recommended).


Yeah was about to say tat and just noticed ur last comment! the form which is having the ValidateUser is ur LoginForm.. ur question is not very clear. So it cant be closed. you should hide it if you dont want it in the background.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜