473,320 Members | 1,883 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,320 software developers and data experts.

How to close parent form and not to close a child form also?

.... say, like MS Word opens another instance of himself when you open
another document.
If you close the first 'Word', the second document remains alive. I can't
figure out how to do the same with

mySecondForm.Show();
myFirstForm.Close(); // also closes mySecondForm too

Thanks.
A lot.
Nov 16 '05 #1
5 9028
Elp
Viper wrote:
... say, like MS Word opens another instance of himself when you open
another document.
If you close the first 'Word', the second document remains alive. I
can't figure out how to do the same with
This is because, as you say, Word opens another instance of himself. I don't
think that there is a Parent/Child relationship between the two Word windows
and this is why closing the first one doesn't cause the second one to close.
mySecondForm.Show();
myFirstForm.Close(); // also closes mySecondForm too


In your case i suggest you to remove the Parent/Child relationship as it
seems to be not appropriate here. Just have 2 top level windows and you'll
be fine.
Nov 16 '05 #2
Hi Viper,

If you close a parent form (MDI Parent form, that is), you close all the
child forms with it. In your example of using Word doc, you are closing the
first child instance of the document... not the parent itself! When you
open any word document, it opens the Word MDI (the engine WINWORD.exe) along
with a child document. In the latest version of OSs (XP and 2003), the
interface is shown as if all the documents are SDI when in fact they are
not. Use your task manager and you'll notice there are as many instances of
word documents as you have opened, but if you look in the process tab, you
will notice only one winword.exe. Try killing the winword.exe process and
effectively, you'd kill all the word documents.

In your example, after showing the second form, the control comes back
to first form (which created and holds a reference to the second form). If
you want to have the second form stay alive after the first form is done
with, then make sure you have a reference to the second form outside the
scope of the first form. Like, add a new form variable in a third class.
One implementation could be...

clsShared.cls:
Nov 16 '05 #3
Viper,

I assume that you run your application using the first form. i.e. your Main
routine is something like:
[STAThread]
static void Main()
{
Application.Run(new FirstForm());
}

Take a look at Application.Run on MSDN library. The overload used above
allows you to specify the main form, and the application installs a Close
event handler on this form which calls the ExitThread method on the
application to close the app.

As an alternative, you can create the form yourself in the Main() routine,
then show the form modelessly using FirstForm.Show(), and then call
Application.Run(). Then your app will keep running until one of the forms
calls Application.ExitThread(). eg:

[STAThread]
static void Main()
{
FirstForm ff = new FirstForm();
ff.Show();
Application.Run();
}

Dont forget to call Application.ExitThread() anywhere where the last visible
form closes, otherwise your application will stay alive with no UI visible.

HTH,
Chris.

"Viper" wrote:
.... say, like MS Word opens another instance of himself when you open
another document.
If you close the first 'Word', the second document remains alive. I can't
figure out how to do the same with

mySecondForm.Show();
myFirstForm.Close(); // also closes mySecondForm too

Thanks.
A lot.

Nov 16 '05 #4
"Chris Ballard" <Ch**********@discussions.microsoft.com> wrote in message
news:01**********************************@microsof t.com...
Viper,
...
Dont forget to call Application.ExitThread() anywhere where the last
visible
form closes, otherwise your application will stay alive with no UI
visible.

HTH,
Chris.


Thank you.

How can I detect, probably in OnClosing, that this is the last Form closing?

Robert
Nov 16 '05 #5
Robert,

The easiest way will be to keep track of each form that you open yourself.
Perhaps you can design a factory object which is used to create each form and
to close each form. This factory class could then detect when the final form
is closed and call ExitThread for you.

Chris.

"Viper" wrote:
"Chris Ballard" <Ch**********@discussions.microsoft.com> wrote in message
news:01**********************************@microsof t.com...
Viper,
...
Dont forget to call Application.ExitThread() anywhere where the last
visible
form closes, otherwise your application will stay alive with no UI
visible.

HTH,
Chris.


Thank you.

How can I detect, probably in OnClosing, that this is the last Form closing?

Robert

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joe D | last post by:
I think this is a simple question. But I am new to JS. Here is what I want to do: From a parent window, open a popup window (child) to get data from user, then user submit the request, close the...
1
by: Martin Douglas | last post by:
Hey guys, maybe someone can help me with some MDI issues I have. A co-worker asked me a very simple question, one that I blew off as trivial, and it has become a time-consuming issue. Simply...
3
by: Isabel | last post by:
How can you close all child browser windows that where open by a parent browser window? I have links on a parent (main) page that opens the child page as a separate browser. However, I need to be...
2
by: Paul | last post by:
Hi this is related to a previous post, hopefully just a bit clearer description o the problem. I have a parent form that opens a new form (child form) while still leaving the parent form open....
0
by: Bill | last post by:
Hi I have a parent child forms. I want the close, maximize, and minimize buttons to be removed. One the child form I have set the maximize and minimize buttons to false. I have the child form...
4
by: LCAdeveloper | last post by:
Help! Another newbie question I'm afraid. I have a toolbar on an MDI form, which I can control OK to produce a child form. When the child form is active, the appropriate MDI parent form toolbar...
4
by: Maarten | last post by:
Hi I'm trying to make something i tought is was simple if i press the cross on the childform to close it, i want it to hide. but when i press a button on the parrent i want to close the child....
0
by: bmwm3 | last post by:
Hi: New to C#, I have a MainForm (parent) that can potentially have multiple child forms (in a tabbed interface). Mainform has closing event defined for "Close All" (through a menu option)...
3
by: =?Utf-8?B?RGF2ZVA=?= | last post by:
I've got a situation in a VB 2003 Windows application with an MDI form and a child form. In certain situations, when the child is closed by the user, I also want to close the MDI parent. Is there...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.