<bdo id='EH6tc'></bdo><ul id='EH6tc'></ul>
      <i id='EH6tc'><tr id='EH6tc'><dt id='EH6tc'><q id='EH6tc'><span id='EH6tc'><b id='EH6tc'><form id='EH6tc'><ins id='EH6tc'></ins><ul id='EH6tc'></ul><sub id='EH6tc'></sub></form><legend id='EH6tc'></legend><bdo id='EH6tc'><pre id='EH6tc'><center id='EH6tc'></center></pre></bdo></b><th id='EH6tc'></th></span></q></dt></tr></i><div id='EH6tc'><tfoot id='EH6tc'></tfoot><dl id='EH6tc'><fieldset id='EH6tc'></fieldset></dl></div>
    1. <small id='EH6tc'></small><noframes id='EH6tc'>

      <tfoot id='EH6tc'></tfoot>
      <legend id='EH6tc'><style id='EH6tc'><dir id='EH6tc'><q id='EH6tc'></q></dir></style></legend>

      1. 动态创建多个文本框 C#

        时间:2023-06-10
        <tfoot id='5nyqG'></tfoot>

            • <bdo id='5nyqG'></bdo><ul id='5nyqG'></ul>

                <tbody id='5nyqG'></tbody>
            • <i id='5nyqG'><tr id='5nyqG'><dt id='5nyqG'><q id='5nyqG'><span id='5nyqG'><b id='5nyqG'><form id='5nyqG'><ins id='5nyqG'></ins><ul id='5nyqG'></ul><sub id='5nyqG'></sub></form><legend id='5nyqG'></legend><bdo id='5nyqG'><pre id='5nyqG'><center id='5nyqG'></center></pre></bdo></b><th id='5nyqG'></th></span></q></dt></tr></i><div id='5nyqG'><tfoot id='5nyqG'></tfoot><dl id='5nyqG'><fieldset id='5nyqG'></fieldset></dl></div>
              <legend id='5nyqG'><style id='5nyqG'><dir id='5nyqG'><q id='5nyqG'></q></dir></style></legend>
              • <small id='5nyqG'></small><noframes id='5nyqG'>

                  本文介绍了动态创建多个文本框 C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这是我的代码.但是我所有文本框的值都是空的.

                  This is my code. But all my textboxes's value is just null.

                      public void createTxtTeamNames()
                      {
                          TextBox[] txtTeamNames = new TextBox[teams];
                          int i = 0;
                          foreach (TextBox txt in txtTeamNames)
                          {
                              string name = "TeamNumber" + i.ToString();
                              txt.Name = name;
                              txt.Text = name;
                              txt.Location = new Point(172, 32 + (i * 28));
                              txt.Visible = true;
                              i++;
                          }
                      }
                  

                  感谢您的帮助.

                  推荐答案

                  数组创建调用只是将元素初始化为null.您需要单独创建它们.

                  The array creation call just initializes the elements to null. You need to individually create them.

                  TextBox[] txtTeamNames = new TextBox[teams];
                  for (int i = 0; i < txtTeamNames.Length; i++) {
                    var txt = new TextBox();
                    txtTeamNames[i] = txt;
                    txt.Name = name;
                    txt.Text = name;
                    txt.Location = new Point(172, 32 + (i * 28));
                    txt.Visible = true;
                  }
                  

                  注意:正如一些人所指出的,为了使这段代码有意义,您需要将每个 TextBox 添加到父 Control.例如 this.Controls.Add(txt).

                  Note: As several people have pointed out in order for this code to be meaningful you will need to add each TextBox to a parent Control. eg this.Controls.Add(txt).

                  这篇关于动态创建多个文本框 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 C# Windows 窗体应用程序中激活拼写检查? 下一篇:在 VB.NET 中检查空的 TextBox 控件

                  相关文章

                • <i id='twV5x'><tr id='twV5x'><dt id='twV5x'><q id='twV5x'><span id='twV5x'><b id='twV5x'><form id='twV5x'><ins id='twV5x'></ins><ul id='twV5x'></ul><sub id='twV5x'></sub></form><legend id='twV5x'></legend><bdo id='twV5x'><pre id='twV5x'><center id='twV5x'></center></pre></bdo></b><th id='twV5x'></th></span></q></dt></tr></i><div id='twV5x'><tfoot id='twV5x'></tfoot><dl id='twV5x'><fieldset id='twV5x'></fieldset></dl></div>

                  <small id='twV5x'></small><noframes id='twV5x'>

                  • <bdo id='twV5x'></bdo><ul id='twV5x'></ul>

                  1. <legend id='twV5x'><style id='twV5x'><dir id='twV5x'><q id='twV5x'></q></dir></style></legend>
                    <tfoot id='twV5x'></tfoot>