Click here to Skip to main content
13,091,093 members (51,332 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I wan to Hide Parent window when it's child will be shown and when child window will be closed again parent window should again visible.

//parent window calling child form//
ChildForm s=new ChildForm();;

//buuttton on child forn to close it//
Form p=(Form)this.Parent;;

It's not working how to do that.
Posted 8-Oct-12 10:26am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

First of all, you should understand that child-form dependency is rendered defunct for forms. You can override it by assigning TopLevel of the form to false, but… don't even try, there is nothing good on doing so; you would simply get one form inside another, which makes no sense.

You code is "not working", just because this.Parent for a form is really null, normally. Also, you should never close a form if you plan on showing again; you better need to hide it (in the FormClosing event, too).

You need to change the design to control the visibility, which is not a problem at all. First of all, I would recommend to use only one form. What are now forms, could be separate panel showing or hiding in the form. If you still need more forms, which I would not recommend, you need to use hiding and showing, not closing. The problem is that the code showing one form and hiding another form should be done in the content where the references to both forms are already known. The forms are pretty much independent; one form is unaware of others, so you need to provide a reference to another form. How to do it, depends on your purpose, but is trivial.

Espen Harlinn 8-Oct-12 18:05pm
Good points :-D
Thank you, Espen.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100