【发布时间】:2009-08-31 09:39:22
【问题描述】:
我创建了自己的用户控件,它只包含一个面板:
当我在设计器中拖动一个 myPanel 对象,然后尝试在其上添加一个按钮时,该按钮实际上已添加到表单的控件中。
是否有我必须设置的属性/属性才能执行此操作,另一种方式来做我想做的事?
public class MyPanel : UserControl
{
private Panel panelMain;
public MyPanel()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.panelMain = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// panelMain
//
this.panelMain.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.panelMain.Dock = System.Windows.Forms.DockStyle.Fill;
this.panelMain.Location = new System.Drawing.Point(0, 0);
this.panelMain.Name = "panelMain";
this.panelMain.Size = new System.Drawing.Size(150, 150);
this.panelMain.TabIndex = 0;
//
// myPanel
//
this.Controls.Add(this.panelMain);
this.Name = "MyPanel";
this.ResumeLayout(false);
}
}
【问题讨论】:
标签: c# winforms user-controls