Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
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 at 8-Oct-12 18:05pm
Good points :-D
Sergey Alexandrovich Kryukov at 8-Oct-12 18:10pm
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
0 CHill60 360
1 Sarvesh Kumar Gupta 238
2 OriginalGriff 218
3 Sergey Alexandrovich Kryukov 153
4 DamithSL 153

Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid