C#自己创建了一个控件,想要动态的加载到PANEL中,怎么实现?求达人赐教

来源:百度知道 编辑:UC知道 时间:2024/06/16 09:33:53

算你 走运,我昨晚刚给人写来个这样的.注意看看注释,应该你就会了.
private void btnClick(object aa,EventArgs ee){
if (aa is Button)
{
MessageBox.Show(((Button)aa).Text);
}
}

private void btnCreate_Click(object sender, EventArgs e)
{
//1st create a panel to contain other controls
System.Windows.Forms.Panel bigPanel = new Panel();
bigPanel.Parent = this;//if we don't set this property then we can't see the panel.we comment this sentence for test it;
bigPanel.Size = new Size(this.Width,this.Height - btnCreate.Height -5);//panel's size
bigPanel.Location = new Point(0,btnCreate.Height + 5);//panel's location
//in order to see the panel ,here we set the bkcolor
bigPanel.BackColor = Color.AliceBlue;
//2nd create a label on the panel
Label myLabel = new Label();
myLabel.Parent = bigPanel;
myLabel.Text = @"test Label!" + (char)13 + "Have Fun";//ascii 13 is change line ch