简体   繁体   中英

winform designer auto-generate has execute control method?

I have create a class inherited from TreeView , and I wanna create some nodes when tree created. So I override the OnCreateControl method and write init code into this method.

在此处输入图片说明

When I drag this control to Form Designer, the auto-generate code has contained nodes. 在此处输入图片说明

Why OnCreateControl method has been executed when I drag the control to Form Designer?

How can I stop this behavior?

Use DesignMode property to determine if your control created at runtime or in VS designer:

protected override OnCreateControl()
{
    base.OnCreateControl();

    if (!this.DesignMode)
    {
       // your code here
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM