我正在尝试在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);
}
}
这是组合框和文本框的屏幕截图
答案 0 :(得分:0)
我测试你的代码并且它有效。有什么问题?
您无法在单行模式下更改文本框高度,在代码中,您将其设置为低于实际高度。
使用此:
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]);
}
答案 1 :(得分:0)
我刚刚更换了createTextBoxes()
这些值:
int width = 69;
int height = 20;
int spacing = 32;
使用createCombo()
值:
int width = 79;
int height = 24;
int spacing = 28;
我得到了以下结果。