问题描述
我的问题如下: 我有一个从 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);
}
好吧,正如您想象的那样,它不起作用。 groupBox 始终具有默认大小,不会根据内容调整大小。分组框内的 TableLayoutPanel 也没有。
解决方法
设置
nrow(data_ave[,1])==nrow(data_ave)
TRUE
和
tLP_PortLayout.AutoSize = true;
为我解决了这个问题。谢谢@Loathing。