首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

怎么让用户控件成为容器控件

2012-01-10 
如何让用户控件成为容器控件我从UserControl中继承下来一个用户控件,在构造函数中设置了SetStyle(ControlS

如何让用户控件成为容器控件
我从UserControl中继承下来一个用户控件,在构造函数中设置了   SetStyle(ControlStyles.ContainerControl,   true);但是在vs2005的ide中,别的控件拖不进我的控件中,只能通过程序动态将别的控件添加到我的这个控件中。我想问一下,如何让其在ide中也能象其它容器控件,比如panel一样,可以将别的控件拖进去

[解决办法]
1. 在工程中引用System.Design.dll
2. 在用户控件中添加以下代码
Imports System.ComponentModel
Imports System.ComponentModel.Design

<Designer(GetType(System.Windows.Forms.Design.ParentControlDesigner), GetType(IDesigner))> _
Public Class UserControl1
' 其它代码
End Class

以上为VB.net代码

[解决办法]
不用引用System.Design.dll,如下就可以了:
[Designer( "System.Windows.Forms.Design.GroupBoxDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ")]
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
}

热点排行