积极答复者
如何让用户控件中的子控件成为设计时的容器

问题
-
定义了一个winform中的用户控件UserControl1,该控件中有一个Panel,其中Panel声明为Public,
在UserControl1前定义了特性 [System.ComponentModel.Designer("System.Windows.Forms.Design.ParentControlDesigner,System.Design ")],
此时UserControl1可以在设计时接受拖放进来的控件,而其中的Panel确不能,
现在我想让UserControl1中的Panel在设计时也可以将其他控件拖入到其中,如何作到这一点呢?
如果不明白我的意思,可以下载我上传的例程:http://g.zhubajie.com/urllink.php?id=5016607uhhkiqhqvbiwgr94
其中紫色部分是Panel。- 已移动 Sheng Jiang 蒋晟Moderator 2009年5月2日 3:42 Windows表单类库设计器问题 ([Loc]From:Visual C#)
答案
-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;namespace WindowsFormsApplication1
{
[Designer(typeof(MyDesigner))]
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Panel MyPanel
{
get { return this.panel1; }
}}
internal class MyDesigner : ControlDesigner
{
private UserControl1 MyControl;public override void Initialize(IComponent component)
{
base.Initialize(component);// Record instance of control we're designing
MyControl = (UserControl1)component;
this.EnableDesignMode(MyControl.MyPanel, "MyPanel");
}
}
}
如何让复合控件的子控件获得设计时支持
http://www.cnblogs.com/feiyun0112/archive/2007/04/30/733230.html
http://feiyun0112.cnblogs.com/- 已标记为答案 Riquel_DongModerator 2009年5月7日 7:36
全部回复
-
我建议你去 Windows Forms Designer 论坛去讨论这个问题, 那里专门讨论这类问题.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. -
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;namespace WindowsFormsApplication1
{
[Designer(typeof(MyDesigner))]
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Panel MyPanel
{
get { return this.panel1; }
}}
internal class MyDesigner : ControlDesigner
{
private UserControl1 MyControl;public override void Initialize(IComponent component)
{
base.Initialize(component);// Record instance of control we're designing
MyControl = (UserControl1)component;
this.EnableDesignMode(MyControl.MyPanel, "MyPanel");
}
}
}
如何让复合控件的子控件获得设计时支持
http://www.cnblogs.com/feiyun0112/archive/2007/04/30/733230.html
http://feiyun0112.cnblogs.com/- 已标记为答案 Riquel_DongModerator 2009年5月7日 7:36
-
我叫董琦,非常高兴能和大家一块讨论.NET开发问题, 我熟悉WinForm开发,熟悉.NET Framework,P/Invoke, COM Interop,希望和大家一块讨论关于.NET开发种的问题。
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.