自定义WinForm控件在从WinForm上删除时无响应
控件利用重写OnCreateControl事件,动态生成控件中的子控件,类似的代码如下(实际的控件创建了多个子控件)
protected override void OnCreateControl()
{
base.OnCreateControl();
if (DesignMode)
{
IDesignerHost host = (IDesignerHost)Site.GetService(typeof(IDesignerHost));
if (!Controls.ContainsKey("pnlContent"))
{
Panel c = host.CreateComponent(typeof(Panel), "pnlContent") as Panel;
c.BackColor = Color.Red;
c.Parent = this;
}
}
}
控件运行和设计都很正常,但是在从winform上删除控件时就没有反应了CPU占用100%,实在是不知道哪儿出问题了,我用了一个简单的例子测试也没出现上述情况,帮我看看可能会在哪儿出问题呢