Winforms: Why do events fire at design-time?

孤人 提交于 2019-12-11 03:38:28

问题


Why are messages displayed at design-time?

My code is :

class Class1 : TextBox
{
    public Class1()
    {
        this.Resize += new EventHandler(Class1_Resize);
    }

    void Class1_Resize(object sender, EventArgs e)
    {
        MessageBox.Show("Resize");
    }
}

Pic :


回答1:


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.



来源:https://stackoverflow.com/questions/3901220/winforms-why-do-events-fire-at-design-time

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