在设计时运行的控件,属性,事件和计时器 [英] Controls, properties, events and timers running in design time

查看:194
本文介绍了在设计时运行的控件,属性,事件和计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果计时器运行了几秒钟,它会引发一个警告发生问题的消息框。



问题是这个消息框甚至在设计时间。如我所追踪的那样,当控件在设计时加载winform时,该属性的默认值为false,似乎它启动了计时器,当它结束时引发了messagebox,每当我打开项目或重建它时,就会发生这种情况。 / p>

我不明白为什么这个行为,因为这应该只在运行时发生,但它让我疯狂,我已经尝试启动计时器,当财产在设置和创建onpropertychanged事件,但这仍然在设计时发生。



任何人都有一个想法如何摆脱这个或如何解决它,以避免这个发生的事情真的令人不安,当程序甚至没有运行时,事情就会发生。



提前感谢



Regards

解决方案

通常的方法是使用 DesignMode pro


如果组件处于设计模式,则为true;否则为false。


所以在您的属性中,在启动计时器之前,首先检查 DesignMode False


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

解决方案

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.

这篇关于在设计时运行的控件,属性,事件和计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆