Winforms:为什么事件在设计时触发? [英] Winforms: Why do events fire at design-time?
本文介绍了Winforms:为什么事件在设计时触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么在设计时显示消息?
Why are messages displayed at design-time?
我的代码是:
class Class1 : TextBox
{
public Class1()
{
this.Resize += new EventHandler(Class1_Resize);
}
void Class1_Resize(object sender, EventArgs e)
{
MessageBox.Show("Resize");
}
}
图片:
推荐答案
因为这是表单设计器的工作方式.实际上,它是在设计时以窗体形式显示控件时实例化的.因此,当您在设计器中调整控件的大小时,将触发消息框的代码.
Because that's the way the Form designer works. It's actually instantiating your control when it displays it in your form at design-time. Thus when you resize the control in the designer, your code for the message box fires.
这篇关于Winforms:为什么事件在设计时触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文