我正在使用.NET 3.5和Windows Forms进行C#项目。我需要设计一个包含多个选项的决策步骤,这些选项需要一些解释性文字。为此,我希望有一组RadioButton来选择一个选项,然后是每个包含说明的附加Label。
我想使单选按钮的标签和包含说明文字的标签保持对齐-我在图像中添加了红线来说明这一点。我可能会在第二个标签上调整一些边距或其他设置,但是一旦用户选择了不同的主题或更改了一些其他设置,那可能就开始显得很奇怪。规范(最可靠)的方法是什么?
不知道为什么我之前没有想到这一点,但是以下方法似乎可行:
关键点似乎是“分隔符”必须在开始时可见,否则该列的大小将为0。
这是我在设计器中的测试表格:
要更改布局,我使用了以下Load处理程序:
private void TestForm_Load(object sender, EventArgs e)
{
// find the column with the spacer and back up its width
int column = tableLayoutPanel.GetColumn(radioButtonSpacer);
int width = tableLayoutPanel.GetColumnWidths()[column];
// hide the spacer
radioButtonSpacer.Visible = false;
// set the column to the fixed width retrieved before
tableLayoutPanel.ColumnStyles[column].SizeType = SizeType.Absolute;
tableLayoutPanel.ColumnStyles[column].Width = width;
}
这是运行时的结果:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句