Click here to Skip to main content
11,647,037 members (79,567 online)
Rate this: bad
good
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();
s.show();
this.hide();
 

//buuttton on child forn to close it//

Form p=(Form)this.Parent;
p.show();
this.close();
 

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

1 solution

Rate this: bad
good
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.

—SA
  Permalink  
Comments
Espen Harlinn at 8-Oct-12 18:05pm
   
Good points :-D
Sergey Alexandrovich Kryukov at 8-Oct-12 18:10pm
   
Thank you, Espen.
--SA

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

  Print Answers RSS
0 jyo.net 510
1 Sergey Alexandrovich Kryukov 423
2 OriginalGriff 398
3 CPallini 339
4 DamithSL 300
0 OriginalGriff 1,253
1 jyo.net 994
2 DamithSL 896
3 Sergey Alexandrovich Kryukov 833
4 CPallini 720


Advertise | Privacy | Mobile
Web03 | 2.8.150804.2 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2015
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