0

我正在尝试在 winforms 应用程序中创建动态文本框。它通过不正确地创建正确的空间。我在这里做错了什么。

private void createTextBoxes()
{

  int width = 69;
  int height = 20;
  int spacing = 32;
  TextBox[] subAmt = new TextBox[12];
  for (int i = 0; i <= 11; ++i)
  {
      subAmt[i] = new TextBox();
      subAmt[i].Size = new Size(width, height);
      subAmt[i].Margin = new Padding(3);
      subAmt[i].Location = new Point(279, (i * height) + spacing); // <-- this is should space it out but does not
      subAmt[i].KeyPress += new KeyPressEventHandler(txtAmt_KeyPress);

       plSubscription.Controls.Add(subAmt[i]);

   }
}

我有类似的组合框代码,它似乎正确地间隔

private void createCombo()
{

  int width = 79;
  int height = 24;
  int spacing = 28;
  for (int i = 0; i <= 11; ++i)
  {
      ComboBox newBox = new ComboBox();
      newBox.Name = "SubYears";
      newBox.DropDownStyle = ComboBoxStyle.DropDownList;
      newBox.Size = new Size(width, height);
      newBox.Location = new Point(145, (i * height) + spacing);

      plSubscription.Controls.Add(newBox);
      fillComboData(newBox);
   }
}

这是组合框和文本框的屏幕截图

在此处输入图像描述

4

2 回答 2

0

我刚刚替换了您的createTextBoxes()这些值:

int width = 69;
int height = 20;
int spacing = 32;

用你的createCombo()价值观:

int width = 79;
int height = 24;
int spacing = 28;

我得到了以下结果。

在此处输入图像描述

于 2013-04-13T10:37:01.517 回答
0

I test your code and it works. what's the problem?


You cant change textbox height in singleline mode, and in your code, you set it lower than actual height.


Use this:

        int width = 69;
        int height = 10;
        int spacing = 0;
        TextBox[] subAmt = new TextBox[12];
        for (int i = 0; i <= 11; ++i)
        {
            subAmt[i] = new TextBox();
            subAmt[i].Size = new Size(width, height);
        // mycode
            height = subAmt[i].Height;
        // ***
            subAmt[i].Margin = new Padding(3);
            subAmt[i].Location = new Point(279, (i * height) + spacing); // <-- this is should space it out but does not

            this.Controls.Add(subAmt[i]);
        }
于 2013-04-13T10:23:14.493 回答