当添加到Form.Controls时,RadioButton更改其高度。

时间:2019-02-17 06:47:35

标签: c# winforms radio-button

我以编程方式在循环中创建了多个RadioButton。我设置了一些属性,最后将新创建的RadioButton添加到Form.Controls列表中。 在将RadioButton添加到Form.Controls之前,其Height属性为24。 在将RadioButton添加到Form.Controls之后的一行,其Height属性为29。 这是循环:

for (int i = 0; i < numberOfRadioButtons; i++)
{
    RadioButton currentRadioButton = new RadioButton();
    currentRadioButton.Font = new Font("Times New Roman", 16, FontStyle.Bold);
    currentRadioButton.Name = "radioButton" + (i + 1).ToString();
    currentRadioButton.Text = currentRadioButton.Name;
    currentRadioButton.AutoSize = true;
    int currentRadioButtonHeight = currentRadioButton.Height; // 24
    this.Controls.Add(currentRadioButton);
    currentRadioButtonHeight = currentRadioButton.Height; // 29
}

我不明白如何向Form.Controls中添加控件来更改控件的高度值。 请帮忙。 预先谢谢你。

1 个答案:

答案 0 :(得分:0)

我发现了! 声明:

currentRadioButton.AutoSize = true;

更改高度。 如果声明是:

currentRadioButton.AutoSize = false;

高度不变。

相关问题