Windows Develop Bookmark and Share   
 index > Windows Forms General > Panel unable to set to 'visible = true'
 

Panel unable to set to 'visible = true'

Hi,

I have a MDI PARENT and several MDI CHILD.
and I put a panel with image inside MDI PARENT container..
but when I call my child form form the menu item, the panel always in front of them.

I already tried a lot ways,
1. mychildform.BringToFront();
2. before showing the childform, I set panel1.visible = false; at MDI PARENT form.
It works for showing the childform, but when I closed the childform, I set like this
//Child form script
Form1 frm = new Form(); //MDI PARENT Form
frm.PanelMaster.Visible=true;

//MDI PARENT script
public bool PanelMaster
{
set { this.panel1.visible=value; }
}

But after the child form closed, panel is not visible.

Please assist.

Thanks

qiux  Tuesday, July 28, 2009 11:38 AM
I don't see how a this.tabPag member could ever be valid in a form. Anyhoo, use logic like this instead:

panel1.Visible = this.MdiChildren.Count == 0;

You can keep your panel visible at all times by docking it. I personally don't think much of the tabbed interface, it is completely unclear which tab belongs to which child window. Perhaps you should consider a real tabbed interface with a TabControl, showing UserControls on its tab pages. You can also embed a form in a tab page by setting its TopLevel property to false.

Hans Passant.
nobugz  Tuesday, July 28, 2009 1:59 PM
Form1 frm = new Form(); //MDI PARENT Form
frm.PanelMaster.Visible=true;

This is new object of your parent form.

Try to change your existing object of MDI Parent form.
Please mark the post as answer if it is helpfull to you because it boosts the members to answer more and more.
_SuDhiR_  Tuesday, July 28, 2009 11:43 AM
Try to change your existing object of MDI Parent form.

I don't undertand. If I used 'Form1' instead of 'frm', I can't get method/property that I created before which in this case is property 'PanelMaster'.
qiux  Tuesday, July 28, 2009 11:46 AM
Handle the child form's FormClosed event in the MDI form and set panel visibility there.
http://blog.voidnish.com
Nishant Sivakumar  Tuesday, July 28, 2009 11:57 AM
How to achieve that? I really don't have any idea. Thanks.
qiux  Tuesday, July 28, 2009 11:59 AM
How to achieve that? I really don't have any idea. Thanks.

Show the code where you create and show your child form.
http://blog.voidnish.com
Nishant Sivakumar  Tuesday, July 28, 2009 12:02 PM
Ok, basically you'd have some code where you do this :

childForm = new ...
childForm.Show()

Just before you show it, add an event handler :

childForm.FormClosed += event-handler

and in this event-handler method, do :

panel1.Visible = ...
http://blog.voidnish.com
Nishant Sivakumar  Tuesday, July 28, 2009 12:20 PM
Hi,
I stuck at here..

I declared an event handler like this, but still got some errors.

private void setVisible()
{
this.panel1.Visible = true;
}

childForm.FormClosed += new EventHandler(setVisible); //this is the error..
childForm.Show();

Is it the correct way?
qiux  Tuesday, July 28, 2009 1:05 PM
Hi,
I stuck at here..

I declared an event handler like this, but still got some errors.

private void setVisible()
{
this.panel1.Visible = true;
}

childForm.FormClosed += new EventHandler(setVisible); //this is the error..
childForm.Show();

Is it the correct way?

The event handler signature does not match.

It needs to be

setVisible(Object sender, EventArgs e)
{
...
}
http://blog.voidnish.com
Nishant Sivakumar  Tuesday, July 28, 2009 1:24 PM
okay i got it worked with below code...

childForm.FormClosed+= new FormClosedEventHandler(FormLifeTimeEvent_Closed);
childForm.WindowState = FormWindowState.Maximized;
//Activate the MDI child form
childForm.Show();

private void FormLifeTimeEvent_Closed(object sender, FormClosedEventArgs e)
{
this.panel1.Visible = true;
}

basically it works. But I wish for every child form before closed will check something logic.

Okay, maybe let me explain some. Actually i want to adopt MDI TAB BROWSING form. So if I open a child form, it will look alike tab page. I follow this tutorial http://www.codeproject.com/KB/cs/MDITabBrowsing.aspx

Why I asked how to set panel visibility to true? because if only 1 form in tab browser, and then I close it so the panel should be visible. Otherwise if I got more than 1 form in tab browser (let's say 3 form), once I closed 1 (so remains 2 forms now) nothing happened for the event handler (or panel should be remain not visible).

Take a look this below code.
private void MDIChild_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
//Destroy the corresponding Tabpage when closing MDI child form
this.tabPag.Dispose();

//If no Tabpage left
if (!tabCtrl.HasChildren)
{
tabCtrl.Visible = false;
//I intend to put something here to make the panel visible = true
// so how to achieve it with the event handler as we did at above?
}
}

Hopefully, I explain clearly. :) thanks.
  • Edited byqiux Tuesday, July 28, 2009 1:47 PMpoor posting
  •  
qiux  Tuesday, July 28, 2009 1:45 PM
I don't see how a this.tabPag member could ever be valid in a form. Anyhoo, use logic like this instead:

panel1.Visible = this.MdiChildren.Count == 0;

You can keep your panel visible at all times by docking it. I personally don't think much of the tabbed interface, it is completely unclear which tab belongs to which child window. Perhaps you should consider a real tabbed interface with a TabControl, showing UserControls on its tab pages. You can also embed a form in a tab page by setting its TopLevel property to false.

Hans Passant.
nobugz  Tuesday, July 28, 2009 1:59 PM
Yes, I can keep my panel visible at all times by docking it in a parent form.
urm.. if I don't use tabbed interface for showing child forms in my application, maybe you have a good suggestion for me? :)
Because I ever worked with third party components which they provided tabbed interface forms, quite easy to use but it's not free.
They look neatly.

Thanks for your suggestions.
qiux  Tuesday, July 28, 2009 2:08 PM
I thought I did give you a good suggestion. What's wrong with it?

Hans Passant.
nobugz  Tuesday, July 28, 2009 2:29 PM
"Perhaps you should consider a real tabbed interface with a TabControl, showing UserControls on its tab pages. You can also embed a form in a tab page by setting its TopLevel property to false."

Did you mean above statement?
qiux  Tuesday, July 28, 2009 2:42 PM
Hi qiux,

Yes, what you mentioned is nobugz's suggestions. He suggest two methods:
1. Add a TabControl to the parent form. Change each child form to a UserControl. Add a TabPage which contains the UserControl to the TabControl.
2. Add a child form to each TabPage and set it TopLevel property to false.

Let me know if this helps.
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Thursday, July 30, 2009 6:02 AM

You can use google to search for other answers

Custom Search

More Threads

• Web Browser and Excel ... Focus Problem ... Please Help
• Scrolling is not smooth
• Please, Help!
• Button index and Building controls Visual Studio 2005
• scroll event for treeview
• How to display assign value to valuemember and display member property of Combobox through LOOP?
• annoying bug
• Treeview Find question
• How can I return an array to Panel.Controls.Add(); function?
• Typing to richtextbox