控件利用重写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%,实在是不知道哪儿出问题了,我用了一个简单的例子测试也没出现上述情况,帮我看看可能会在哪儿出问题呢
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%,实在是不知道哪儿出问题了,我用了一个简单的例子测试也没出现上述情况,帮我看看可能会在哪儿出问题呢
解决方案 »
- C# mapx5.0 轨迹回放 求大侠帮忙
- 数据导出到excel
- 在线求一简单正则表达式
- 怎么回事?Object reference not set to an instance of an object?
- Bug管理系统
- 200分求经典WinForm的C#程序
- 求c#对access操作源码
- c#中的简单问题?谢谢了哦!
- 请教高手:如何在一个Repeater中绑定一个问题跟多个答案,但答案有单选跟多选。。。。。。。。。。。。。。。
- while((Thread1.ThreadState&ThreadState.Unstarted)!=0);是什么意思啊
- 数据结构:如何实现一般的树结构?(C# or java)
- 如何在C#中 调用存储过程
如果觉得调试有困难,不妨使用Microsoft CLR Debugger来进行调试。。
写控件是一件很麻烦的工作,不过也能学会很多,楼主多加把劲。。
其中一个类中有对另一个类引用的属性,我把这个属性不赋值就没问题了,不过真不知道是为什么呢。
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.ParentPanel=this;//就是在这个地方出的问题把这个地方注释掉立马没问题了
c.Parent = this;
}
}
}