为什么在 UserControl 中没有正确更新 Visible 属性?属性、正确、UserControl、Visible

2023-09-07 15:19:22 作者:自然萌的童鞋

有时我的 UserControl 的 Visible 属性没有正确更新.它发生在我的应用程序启动时,在 OnFontChanged 中,从 InitializeComponent 内部触发,可能是因为尚未设置其他一些东西.我就是不知道是什么.

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 是一个 UserControl,位于另一个 UserControl 中.显然,这只发生在尝试将值设置为 true 时.vScrollBar 已经创建了它的句柄,正如 IsHandleCreated 上的手表所说的那样.

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.

推荐答案

如果Form还没有加载,可能还是会显示false.尝试在 Form 的 OnLoad 事件中设置它.

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

 
精彩推荐
图片推荐