Curiosity is kicking out again. I've been using the user control .Visible
and .Hide()
method for a long time. So where does a user-control go when the visibility of it is set to false?
views:
76answers:
3It doesn't go anywhere - it stays in memory. It's just that its not visible. Being visible really means that it has to paint its area when requested and it can receive focus and user actions.
When you set the Visible property on a control it essentially tells the web server not to return the HTML markup for the control in the response. It does, however, keep the control's information in the viewstate so you can keep working with it in your code.
Oops - sorry. I thought you were talking about ASP.NET and not WinForms. My bad.
I'd agree with VinayC (+1 btw).
Also, even though the control doesn't paint itself or respond to user events through the UI you can still exercise it programmatically or indeed use its data.
For example you could have an invisible window that logs posted message data.
You actually use this functionality quite a lot without thinking about it, take your Form control for example. For a modal dialog box you create it, set property values whilst it is hidden then make it visible with the ShowDialog() method.