0

hi there,

i have two forms in my project, what i want is when i cilck the close icon on top of the form the login form should be displayed, how can i do this in C#??

2
Contributors
6
Replies
8
Views
7 Years
Discussion Span
Last Post by judithSampathwa
0

Add "FormClosing" event to your form. And use this code:

private void Form_Closing(object sender, FormClosingEventArgs e)
{
    // Remove these 2 lines if the current form is not the default form of your application.
    e.Cancel = true;
    this.Hide();
    
    LoginForm loginForm = new LoginForm();
    loginForm.Show();
}

Thanks

Edited by farooqaaa: n/a

0

Add "FormClosing" event to your form. And use this code:

private void Form_Closing(object sender, FormClosingEventArgs e)
{
    // Remove these 2 lines if the current form is not the default form of your application.
    e.Cancel = true;
    this.Hide();
    
    LoginForm loginForm = new LoginForm();
    loginForm.Show();
}

Thanks

it dosen't work it gives an stack overflow exception???

why is that???????????


thanxxxxx

0

I've tested the code and its working perfectly. There might be something wrong with your code. Can you post your code?

1

Okay. You are making a mistake there. When you call this.Close() FormClosing event is fired. But inside FormClosing event you've called this.Close() again which causes a stackoverflow.

Here's the working code:

private void btnPClose_Click(object sender, EventArgs e)
{
    this.Close();
}

private void frmProposalInProgress_FormClosing(object sender, FormClosingEventArgs e)
{
   new frmLogin().Show();
}

Thanks

0

Okay. You are making a mistake there. When you call this.Close() FormClosing event is fired. But inside FormClosing event you've called this.Close() again which causes a stackoverflow.

Here's the working code:

private void btnPClose_Click(object sender, EventArgs e)
{
    this.Close();
}

private void frmProposalInProgress_FormClosing(object sender, FormClosingEventArgs e)
{
   new frmLogin().Show();
}

Thanks

hey it dosen't work properly

the thing is when i login and go to the second form the login form displays???

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.