Windows Develop Bookmark and Share   
 index > Windows Forms General > Parent, child forms check if open or closed
 

Parent, child forms check if open or closed

Hi all,

I'm new to c# and currently working on a project containing mdi forms.
This is how the project is layed out.
Parent form is called Street_Index. This contians a menu strip which can open 2 different forms.
* Street_Search
* Office_Search

Within the Street_search form there is a button that i click that returns the results in another form called Search_Results.
Search Results contains a grid and on double clicking the column of the grid it returns the results of that row back to Street_Search form which displays them in textboxes, grid, combobox, etc..

Within the Office_Search form there is also a button that opens the Search_Results form and then from there you can double click on the grid within Search_Results and open up Street_Search form which will display the results as previous.


Now onto the question. What is the cleanest possible way to check to see if a childform is open or not and if it is refresh it or bring it into focus?

Thanks in advance
Take care all.





RainX  Tuesday, August 28, 2007 5:00 PM

This is just a thought, and may or may not apply to your particular solution:

Instantiate your child forms when the app starts or early on. Use Show/Hide and override the Close by the user. Show-ing a minimized MDI child may restore it if it's minimized within the parent - you'll have to test that.

In the end, you're reusing your child forms, not creating umpteen multiples of them, so maybe that works for you and maybe it doesn't.

Chris

Chris Langsenkamp  Tuesday, August 28, 2007 5:25 PM

Hi RainX,

You can loop through all MDI child forms and check the type of each form. If these is a form whose type matched the type of the form you want to open, you need to create a new instance, you just need to make the match form as the active form. Try the following code:

Code Snippet

MDIForm

publicpartialclassMainFormForm

public

privatevoidobjectEventArgs

int

Form

iftypeofChildFrm1out

newChildFrm1

this

else

privatevoidobjectEventArgs

int

Form

iftypeofChildFrm2out

newChildFrm2

this

else

boolTypeoutint

intthis

forint

ifthis

returntrue

returnfalse

Hope this helps.
Best regards.

Rong-Chun Zhang  Thursday, August 30, 2007 9:18 AM
The cleanest possible way is to let the child form raise an event, picked up by the MDI parent. Who can then decide how other possible instantiated children should be notified.
nobugz  Thursday, August 30, 2007 4:15 PM

This is just a thought, and may or may not apply to your particular solution:

Instantiate your child forms when the app starts or early on. Use Show/Hide and override the Close by the user. Show-ing a minimized MDI child may restore it if it's minimized within the parent - you'll have to test that.

In the end, you're reusing your child forms, not creating umpteen multiples of them, so maybe that works for you and maybe it doesn't.

Chris

Chris Langsenkamp  Tuesday, August 28, 2007 5:25 PM

Hi RainX,

You can loop through all MDI child forms and check the type of each form. If these is a form whose type matched the type of the form you want to open, you need to create a new instance, you just need to make the match form as the active form. Try the following code:

Code Snippet

MDIForm

publicpartialclassMainFormForm

public

privatevoidobjectEventArgs

int

Form

iftypeofChildFrm1out

newChildFrm1

this

else

privatevoidobjectEventArgs

int

Form

iftypeofChildFrm2out

newChildFrm2

this

else

boolTypeoutint

intthis

forint

ifthis

returntrue

returnfalse

Hope this helps.
Best regards.

Rong-Chun Zhang  Thursday, August 30, 2007 9:18 AM
The cleanest possible way is to let the child form raise an event, picked up by the MDI parent. Who can then decide how other possible instantiated children should be notified.
nobugz  Thursday, August 30, 2007 4:15 PM

You can use google to search for other answers

Custom Search

More Threads

• client server windows application in LAN,can work just provide server ip address in connection string
• How change the font style to bold for a array of label in vb.net
• Parent Child Forms
• duplicate a control and its contents?
• Timer and windows forms
• Different languages in Resource File.
• Dragging a form around the screen
• ASCII to Binary Conversion
• ribbon and form caption
• VB.NET2003-Tool Bar and the locaization