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.