1

I want to place a new button just below the button which initialized it. But this one is in a panel and not in the Form.

The panel is located at (45,213) in the form and the button is at (31 - 40) in the panel. The panel will move in the future; that's why I would like to take the panel as a reference, not the form.

My code is

private void addstrat3_i_Click(object sender, EventArgs e)
{
    panel3strat.Width += 200;
    Button addstrat3_2 = new Button();
    this.Controls.Add(addstrat3_2); 
    addstrat3_2.Size = new Size(210, 41);
    addstrat3_2.Location = new Point(31,100);
    addstrat3_2.Visible = true;
    this.Controls.Add(addstrat3_2); 
 }
4

1 回答 1

4

每个包含类型都有它自己的 Controls 属性。

代替:

this.Controls.Add()

你可以使用:

myPanel.Controls.Add()

这样,您添加的控件与正确的父对象相关联。

于 2013-04-29T15:34:19.140 回答