c# - 添加到 Form.Controls 时,RadioButton 会更改其高度
问题描述
我在一个循环中以编程方式创建了许多 RadioButtons。我设置了它的一些属性,最后将新创建的 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 添加控件如何更改控件高度的值。请帮忙。先感谢您。
解决方案
我发现!该声明:
currentRadioButton.AutoSize = true;
改变高度。如果声明是:
currentRadioButton.AutoSize = false;
高度不变。
推荐阅读
- java - 如何使用 GridBagLayout 在 Java Swing 中“模拟”一个 12 列网格
- sql - 如何从选择查询更新表中的列?
- javascript - 循环中的 HTTP 请求
- puppeteer - 如何从 ElementHandle 转到 DOM 元素
- django - 使用带多选的中间表与管理员的 Django M2M 关系问题
- c# - 创建一个名称为目录路径的新文件
- rest - Rest 或 RestQL 或 Falcor 或 GraphQl
- c# - 如何将 swagger 与 Azure Active Directory OAuth 集成
- swift - window.windowController 在 windowWillClose() 内为零,但不在 viewDidAppear() 内
- angular - 角度“as”关键字实际上在做什么?