Controls, properties, events and timers running in design time

[亡魂溺海] 提交于 2019-12-11 03:24:29

问题


Im using some custom control in vb.net, where I have a boolean property that, whenever it changes, it starts a timer if it's value is false or stops if it's true.

If the timer runs for several seconds, it raises a messagebox that warns of a problem happening.

The problem is that this messagebox shows even in design time. As I have traced, the default value for the property is false when the control loads in the winform in design time, it seems it starts the timer and when it ends raises the messagebox, this happens whenever I open the project or rebuild it.

I don't get why this behaviour, as this should only happen at run time but it's driving me crazy, I have tried starting the timer directly when the property changes in the setter and creating "onpropertychanged" events, but this still happens in design time.

Anyone has an idea of how to get rid of this or how to solve it to avoid this of happening, is really disturbing that things happens when the program isn't even running.

Thanks in advance.

Regards


回答1:


The common way is to use the DesignMode property of the control.

true if the Component is in design mode; otherwise, false.

So in your property, before starting the timer, first check if DesignMode is False.



来源:https://stackoverflow.com/questions/12491032/controls-properties-events-and-timers-running-in-design-time

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