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

梦想与她 提交于 2019-12-01 05:23:58

问题


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.

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.


回答1:


It may still show false if the Form has not loaded. Try setting it in the Form's OnLoad event.




回答2:


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.



来源:https://stackoverflow.com/questions/3780140/why-is-the-visible-property-not-correctly-updated-in-a-usercontrol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!