Question Visibility Issues on form opened on the 2nd time.

alvinucsk

New member
Joined
Apr 9, 2012
Messages
1
Programming Experience
5-10
Hi there i have 2 forms

Form #1: a button when click, loads form 2
Form #2: has a label... On form load it has
Label1.Text = String.Format("Label.Visible property is {0}", Label1.Visible)
...

behavior, when click the button from form 1, and loads form 2... it shows that "Label.Visible property is True"

and close Form 2, directs me back to form1.

when i click the button on form 1 to load form 2. it shows "Label.Visible property is False"

and it displays the text but has Label1.Visibility as False. any1 can explain why?
Here is the code... Im running VS2010 with .net 4.0 framework
 

Attachments

  • WindowsApplication12.zip
    20 KB · Views: 21
Last edited by a moderator:
The Label's Visible property is False when you get it and put it into the Text property. After that the Visible property changes to True but you don't change the Text.
 
A form displayed with ShowDialog is not disposed when user closes it, so your code is reusing the same form instance each time you call ShowDialog.
First time Visible property value is retrieved it is the default value or value set in designer.
Then form is "closed" which in this case means hidden (actually the control handles are destroyed), and at this state the control will return False for visibility (a control without a window handle can't be visible).
Next time you show it Load handler evaluates the current visibility state which is thus False.
If you check at time of Shown event you will see that it now is visible again.
 
Back
Top