Winforms: Why do events fire at design-time?
Why are messages displayed at design-time?
My开发者_StackOverflow code is :
class Class1 : TextBox
{
public Class1()
{
this.Resize += new EventHandler(Class1_Resize);
}
void Class1_Resize(object sender, EventArgs e)
{
MessageBox.Show("Resize");
}
}
Pic :
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.
精彩评论