[英]C# Winforms autosize GroupBox
我的问题如下:我有一个从 xml 文件中获取项目的代码。 这应该被解析并相应地生成选项卡、组框和标签。
我有以下代码:
foreach(XmlNode function in root.SelectNodes("function"))
{
string functionName = function.SelectSingleNode("name").InnerText;
TabPage tabPage = new TabPage(functionName);
FlowLayoutPanel fLP_Layout = new FlowLayoutPanel();
foreach(XmlNode port in function.SelectNodes("Port"))
{
string portName = port.SelectSingleNode("name").InnerText;
GroupBox gB = new GroupBox();
gB.Text = portName;
TableLayoutPanel tLP_PortLayout = new TableLayoutPanel();
tLP_PortLayout.Location = new Point(5, 20);
tLP_PortLayout.ColumnCount = 2;
var y = 20;
foreach(XmlNode register in port.SelectNodes("Register"))
{
Label l_register = new Label();
l_register.Location = new Point(5, y);
l_register.Text = register.SelectSingleNode("name").InnerText;
TextBox tB_Value = new TextBox();
tB_Value.Location = new Point(50, y - 4);
tLP_PortLayout.Controls.Add(l_register);
tLP_PortLayout.Controls.Add(tB_Value);
y += 20;
}
gB.Controls.Add(tLP_PortLayout);
fLP_Layout.Controls.Add(gB)
}
tabPage.Controls.Add(fLP_Layout);
tabControl1.TabPages.Add(tabPage);
}
而且,正如您可以想象的那样,它不起作用。 组框始终具有默认大小,并且不会根据内容调整大小。 组框内的 TableLayoutPanel 也没有。
环境
tLP_PortLayout.AutoSize = true;
和
gB.AutoSize = true
为我解决了这个问题。 谢谢@Loathing。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.