Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.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
我希望在运行时单击visual studio(C#)中的按钮时添加文本框。我该怎么做?_C#_.net_Button_Runtime - Fatal编程技术网

我希望在运行时单击visual studio(C#)中的按钮时添加文本框。我该怎么做?

我希望在运行时单击visual studio(C#)中的按钮时添加文本框。我该怎么做?,c#,.net,button,runtime,C#,.net,Button,Runtime,我想创建一个代码段,当我按下按钮时,文本框必须出现在某个位置。这必须在运行时发生,每次我按下按钮的次数。您可以执行以下操作: public void ButtonAddNewTextbox_Click(object sender, EventArgs e) { TextBox textbox = new TextBox(); textbox.Location = new Point(); // specify position inside the constructor

我想创建一个代码段,当我按下按钮时,文本框必须出现在某个位置。这必须在运行时发生,每次我按下按钮的次数。

您可以执行以下操作:

public void ButtonAddNewTextbox_Click(object sender, EventArgs e) 
{
   TextBox textbox = new TextBox();
   textbox.Location = new Point(); // specify position inside the constructor

   Controls.Add(textbox);
}
注意:我没有为点对象指定
X
Y
坐标。您可以通过执行以下操作自行设置:

Point p = new Point();
p.X = 100;
p.Y = 100;
每个文本框的这些值需要不同,以便正确地隔开