472,779 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 software developers and data experts.

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 10823
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Wortelvisje | last post by:
Hello, What I want to do is quit simple: if the does clicks on the cross at the right top of the screen I want to catch this event and check a few things before closing the window. The only...
1
by: Eric Cadwell | last post by:
We're running Load Runner to test a large 1.0 based WinForms application. I'm getting the following exception when opening and closing a form 400 - 450 times. The form contains several controls and...
5
by: D Witherspoon | last post by:
I use the following code to open up a form. ------------------------------------------------------- If fImage Is Nothing Then fImage = New frmImage End If fImage.Show()
5
by: Peter yeshew | last post by:
Is it possible to forbid closing the form through the File- Close menu ? On my form i have a command button called CmdDeleteInvoice. When this command button is visible ,i want to forbid the user...
6
by: Gary Miller | last post by:
Does anyone know how to detect a modeless form on closing by the form that invoked the modeless form? form.Show();
5
by: smhaig | last post by:
In a vb 6 app in the activate event I was able to do some testing and if something failed, I was able to exit the form and return to the caller form. I have tried everything and searched web but...
3
by: Sherwood | last post by:
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...
1
by: Dachshund Digital | last post by:
Can some one recreate this issue? Create WindowApplication Using .NET 2.0/Visual Studio Express VB Button on Main Form to open 2nd Form as ShowDialog Button on 2nd Form to open 3rd Form as...
9
by: G .Net | last post by:
Hi I'm soooo sorry but I've had to re-post this message again. I have no idea what has been happening but for some reason I couldn't seem to be able to see messages that I'd posted earlier. ...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.