473,385 Members | 1,890 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,385 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 9037
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.