469,353 Members | 2,066 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,353 developers. It's quick & easy.

Closing a calling form (C#.Net)

Greetings,

I have the following code (which displays a second form), but it is not
working as expected. I want to close the calling form after the dismissing
the second form. However, the second form never displays with the code I
have below. Any suggestions? [Note: I have also placed the code,
"frmMain.ActiveForm.Close();" in the "Click" event of the command button on
the second form, but this is not working either].

ActiveForm.Hide();
frmInstructions frmInstructions = new frmInstructions();
frmInstructions.Show();
ActiveForm.Close();

Thanks!
--
Sherwood
Jul 21 '05 #1
3 10696
Sherwood, chances are the form is "closing" before it displays. If you need
to suspend the main thread for the subform to open and then close, use the
following...

frmInstructions frmInstructions = new frmInstructions();
DialogResult dr = frmInstructions.ShowDialog();

this will also tell you how the form was closed, if you are interested...Chuck

"Sherwood" wrote:
Greetings,

I have the following code (which displays a second form), but it is not
working as expected. I want to close the calling form after the dismissing
the second form. However, the second form never displays with the code I
have below. Any suggestions? [Note: I have also placed the code,
"frmMain.ActiveForm.Close();" in the "Click" event of the command button on
the second form, but this is not working either].

ActiveForm.Hide();
frmInstructions frmInstructions = new frmInstructions();
frmInstructions.Show();
ActiveForm.Close();

Thanks!
--
Sherwood

Jul 21 '05 #2
Hi Chuck,

Thanks so much for the code. The dialog is closing. However, when the
routine finishes I am still in "run" mode. Is there something obvious I am
overlooking in the code below? Do I need to "unload" the main form in order
to exit "run" mode?

private void btnClickMe_Click(object sender, System.EventArgs e)
{
ActiveForm.Hide();
frmInstructions frmInstructions = new frmInstructions();
DialogResult dr = frmInstructions.ShowDialog();
}

Thanks again!

Sherwood

"chuck rudolph" wrote:
Sherwood, chances are the form is "closing" before it displays. If you need
to suspend the main thread for the subform to open and then close, use the
following...

frmInstructions frmInstructions = new frmInstructions();
DialogResult dr = frmInstructions.ShowDialog();

this will also tell you how the form was closed, if you are interested...Chuck

"Sherwood" wrote:
Greetings,

I have the following code (which displays a second form), but it is not
working as expected. I want to close the calling form after the dismissing
the second form. However, the second form never displays with the code I
have below. Any suggestions? [Note: I have also placed the code,
"frmMain.ActiveForm.Close();" in the "Click" event of the command button on
the second form, but this is not working either].

ActiveForm.Hide();
frmInstructions frmInstructions = new frmInstructions();
frmInstructions.Show();
ActiveForm.Close();

Thanks!
--
Sherwood

Jul 21 '05 #3
Sherwood, I am not sure what you want to do. If you want to close the form
that is displaying the insturctions then your code should look like...
private void btnClickMe_Click(object sender, System.EventArgs e)
{
frmInstructions frmI = new frmInstructions();
DialogResult dr = frmI.ShowDialog();
this.Close();
}

I am not sure what you have your "hide" in there. If you want the main form
to disappear while the Instructions are up then that will work.

"Sherwood" wrote:
Hi Chuck,

Thanks so much for the code. The dialog is closing. However, when the
routine finishes I am still in "run" mode. Is there something obvious I am
overlooking in the code below? Do I need to "unload" the main form in order
to exit "run" mode?

private void btnClickMe_Click(object sender, System.EventArgs e)
{
ActiveForm.Hide();
frmInstructions frmInstructions = new frmInstructions();
DialogResult dr = frmInstructions.ShowDialog();
}

Thanks again!

Sherwood

"chuck rudolph" wrote:
Sherwood, chances are the form is "closing" before it displays. If you need
to suspend the main thread for the subform to open and then close, use the
following...

frmInstructions frmInstructions = new frmInstructions();
DialogResult dr = frmInstructions.ShowDialog();

this will also tell you how the form was closed, if you are interested...Chuck

"Sherwood" wrote:
Greetings,

I have the following code (which displays a second form), but it is not
working as expected. I want to close the calling form after the dismissing
the second form. However, the second form never displays with the code I
have below. Any suggestions? [Note: I have also placed the code,
"frmMain.ActiveForm.Close();" in the "Click" event of the command button on
the second form, but this is not working either].

ActiveForm.Hide();
frmInstructions frmInstructions = new frmInstructions();
frmInstructions.Show();
ActiveForm.Close();

Thanks!
--
Sherwood

Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Wortelvisje | last post: by
5 posts views Thread by Peter yeshew | last post: by
6 posts views Thread by Gary Miller | last post: by
5 posts views Thread by smhaig | last post: by
3 posts views Thread by Sherwood | last post: by
9 posts views Thread by G .Net | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.