Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the Visible property not correctly updated in a UserControl?

Sometimes my UserControl's Visible property does not get updated correctly. It happens at my app's boot time, in OnFontChanged, fired from inside InitializeComponent, probably because some other stuff has not been set up yet. I just can't find out what.

alt text

vScrollBar is a UserControl and is inside another UserControl. Apparently, this only happens when trying to set the value to true. vScrollBar already has its handle created, as a watch on IsHandleCreated says it's true.

like image 937
Gabriel Avatar asked Sep 23 '10 15:09

Gabriel


People also ask

What is the purpose of the Visible property?

You can use the Visible property to hide a control on a form or report by including the property in a macro or event procedure that runs when the Current event occurs. For example, you can show or hide a congratulatory message next to a salesperson's monthly sales total in a sales report, depending on the sales total.

Which control is not Visible at run time?

Although code in your control may still run while invisible, you will not be able to interact with the control through the user interface. If you want to create an invisible control that still responds to user input (for example, mouse clicks), you should create a transparent control.

What control property is used to hide the object during run time?

Visible property is used to hide the object at run time. Width property sets the TextBox to the desired width at design time.


1 Answers

Reading the Visible property gives you the actual visibility state of the control, not the 'intended' state. Which will always be false in the InitializeComponent() method, the form or control isn't visible yet until after the Load event runs. It will also be false if the container control isn't visible.

like image 53
Hans Passant Avatar answered Oct 04 '22 14:10

Hans Passant