【发布时间】:2020-11-28 07:53:59
【问题描述】:
堆栈溢出!我来过这里多次,我总是设法找到我问题的答案!但是现在我提出了一个我找不到解决方案的问题,这里有一点 c#,当你按下按钮时会生成一个新的 TextBox,我如何在创建后移动文本框?
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int cLeft = 1;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
AddNewTextBox();
}
public System.Windows.Forms.TextBox AddNewTextBox()
{
System.Windows.Forms.TextBox txt = new System.Windows.Forms.TextBox();
this.Controls.Add(txt);
txt.Top = cLeft * 25;
txt.Left = 100;
txt.Text = "TextBox " + this.cLeft.ToString();
cLeft = cLeft + 1;
return txt;
}
}
}
【问题讨论】:
-
var createdTextBox = AddNewTextBox(); createdTextBox.Location = new Point(x, y);. -
这只适用于文本框的一个实例
标签: c# windows visual-studio winforms