我的问题如下:我有一个从xml文件中获取项目的代码。应该对其进行解析,并生成相应的选项卡、分组框和标签。
我有以下代码:
代码语言:javascript运行复制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也不需要。