none
How does windows forms remember the visible property

    Question

  • I searched the forums, the one similar question I found was not answered, so I'll try to ask it more clearly.

    Say you have a panel and a button on that panel.  In the designer you put Visible on both to true.  If you set the panel Visible = false, the button's Visible property is turned to false.  When you set the visible property back to true, the button visible property goes back to true. Ok, I understand that completely.   If the button is set to false in the designer, (or in the code), when the panel changes visibility, the button Visible always remains false.   Exactly as one want it.

    However, say I want to clone the appearance of the panel and button.  If the panel is invisible when I start the clone, I cannot know why button.visible is false.  Because the designer wanted it false or because children are turn false.  So I don't know how to set the Visible property of my clone.

    My question is how can I figure out the original value of the visible as it was set by the designer?   I used reflection to look at all the private properties and private fields but could not find anything that seemed to keep the original value.    I don't want to do something like an external object that keeps the actual visible properties.

    Any Idea?  This is causing my hair to fall out
    Tuesday, November 03, 2009 6:22 PM

Answers

  • Not a good solution but since you don't want to write your custom control you can get the value by.

    bool isButtonVisible=false;
    if(panel1.Visible)
    {
    isButtonVisible=button1.Visible;
    }
    else
    {
    panel1.Visible=true;
    isButtonVisible=button1.Visible;
    panel1.Visible=false;
    }

    Tuesday, November 03, 2009 6:38 PM

All replies

  • Not a good solution but since you don't want to write your custom control you can get the value by.

    bool isButtonVisible=false;
    if(panel1.Visible)
    {
    isButtonVisible=button1.Visible;
    }
    else
    {
    panel1.Visible=true;
    isButtonVisible=button1.Visible;
    panel1.Visible=false;
    }

    Tuesday, November 03, 2009 6:38 PM
  • Thanks for the reply, For some reason I missed this your reply, it does work for objects embedded one level down and can be made to work for nested panels. 

    My actual need was a little more complicated as it was in a nested deeply menu object.  One has to walk the owner propery (rather than the parent property) for one level.  I haven't done multiple levels....

    Again thanks

    Wednesday, December 02, 2009 4:14 PM