我想知道是否有人可以帮助我改进我的代码(?)
三个星期前,我决定学习C#/ C++(决定从c#开始)并且我正在尽我所能,但我在理解一些基础知识方面遇到了问题 - 例如数组.
我想添加"x"文本框(其中"x"是numericUpDown的值),点击按钮.
我找到了一个解决方法如何做到这一点,但我有这种感觉,可以用不同的(更好的)方式编写它(我假设高级程序员会使用列表或数组).
如果我错了,请原谅我,正如我之前提到的那样 - 我是新人并尽我所能去学习.
这是我的代码:
private void button1_Click(object sender, EventArgs e)
{
if (numericUpDown1.Value == 1)
{
txtbx1.AutoSize = true;
Controls.Add(txtbx1);
txtbx1.Location = new Point(70, 100);
}
else if (numericUpDown1.Value == 2)
{
txtbx1.AutoSize = true;
Controls.Add(txtbx1);
txtbx1.Location = new Point(70, 100);
txtbx2.AutoSize = true;
Controls.Add(txtbx2);
txtbx2.Location = new Point(70, 130);
}
else if (numericUpDown1.Value == 3)
{
txtbx1.AutoSize = true;
Controls.Add(txtbx1);
txtbx1.Location = new Point(70, 100);
txtbx2.AutoSize = true;
Controls.Add(txtbx2);
txtbx2.Location = new …Run Code Online (Sandbox Code Playgroud) c# ×1