473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 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 10862
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.