我是C#的初学者,我想创建一个创建按钮的按钮。 但这些按钮永远不会出现......
请找到我的代码:
private void addstrat3_i_Click(object sender, EventArgs e)
{
panel3strat.Width += 200;
Button addstrat3_2 = new Button();
addstrat3_2.Size = new Size(210, 41);
addstrat3_2.Location = new Point(50,50);
addstrat3_2.Visible = true;
}
非常感谢
答案 0 :(得分:10)
您必须使用Controls
属性在表单上添加按钮(或任何其他控件),用于示例:
private void addstrat3_i_Click(object sender, EventArgs e)
{
panel3strat.Width += 200;
Button addstrat3_2 = new Button();
addstrat3_2.Size = new Size(210, 41);
addstrat3_2.Location = new Point(50,50);
addstrat3_2.Visible = true;
// add control
this.Controls.Add(addstrat3_2);
}
答案 1 :(得分:3)
您需要将该按钮添加到表单中。
this.Controls.Add(addstrat3_2);