Search code examples
vb.netformshideshowsplitcontainer

VB.NET: Is form.show() called?


I have a very simple question.

I call .show() and .hide() on a form and then I want to determine the current state. I've been checking .visible to determine if the form is visible, but I've stumbled uppon a problem. My form is being rendered inside a SplitContainer which I collapse each time I hide the form. So, by logic once I hide the form with .hide() it is no longer visible, and since I have collapsed it's container, even if I call .show() it would still NOT be visible couse it's container is closed.

So, how can I simply check if .show() has been called rather than checking if the form is visible.

The final goal is to show() / hide() the form along with collapsing / un-collapsing the container.

Thanks in advance!

P.S.: I know I could simply check the container and show the form accordingly, but my form also supports detaching from the container, so that wont work for me.


Solution

  • You cannot take a shortcut here. By tinkering with the form's TopLevel property so you can put it on a panel, the form's Visible property is no longer a reliable indication whether you last called Show() or Hide(). Because reading the property only tells if the user can see the form. If the control's Parent is not visible then the control's Visible property returns False, even if you set it to True.

    The workaround is simple, just use a Boolean variable to keep track. Or just call Show and Hide when you need it be in/visible, calling Show when it is already visible or Hide when it is already invisible doesn't matter.