Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 按钮在面板中的位置不在表单中_C#_.net_Button - Fatal编程技术网

C# 按钮在面板中的位置不在表单中

C# 按钮在面板中的位置不在表单中,c#,.net,button,C#,.net,Button,我想在初始化它的按钮下方放置一个新按钮。但这是一个面板,而不是形式 面板位于表格中的45213处 按钮在面板上的31-40。 该小组将在未来采取行动;这就是为什么我想把小组作为参考,而不是表格 我的代码是 private void addstrat3_i_Click(object sender, EventArgs e) { panel3strat.Width += 200; Button addstrat3_2 = new Button(); this.Controls

我想在初始化它的按钮下方放置一个新按钮。但这是一个面板,而不是形式

面板位于表格中的45213处 按钮在面板上的31-40。 该小组将在未来采取行动;这就是为什么我想把小组作为参考,而不是表格

我的代码是

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); 
 }

每个包含类型都有自己的控件属性

而不是:

this.Controls.Add()
您可以使用:

myPanel.Controls.Add()

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

每个包含类型都有自己的控件属性

而不是:

this.Controls.Add()
您可以使用:

myPanel.Controls.Add()

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

没问题。请随意将这个答案标记为正确,在左边打勾,这样将来如果有人看到它,它也会帮助他们。没问题。请随意将此答案标记为正确,并在左侧打勾,以便将来其他人看到此答案时,也会对他们有所帮助。