创建一个按钮来创建按钮
本文关键字:创建 按钮 一个 | 更新日期: 2023-09-27 18:11:26
我是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;
}
Thanks to lot
您必须使用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);
}
您需要将按钮添加到表单中。
this.Controls.Add(addstrat3_2);