根据 XML 文件的内容,程序在运行时必须动态创建文本框和标签。我想在组框中按以下方式组织此控件:
[label1] [textbox1] [label2] [texbox2] [label3] [textbox]
[label4] [textbox4] [label5] [textbox5] [...]
所以。
但我不知道如何计算X
和Y
值。我尝试了几种解决方案,但没有运气。在我当前的实现下方,每行放置标签和文本框:
[label1] [texbox1]
[labe2] [texbox2]
所以。
//list the disiciplanas from XML file
//into combobox control.
for (int i = 0,
label_X = 20, label_Y = 20,
textbox_X = 74, textbox_Y = 20,
len = materias[0].ChildNodes.Count,
line = 0, tmp_pos = 20;
i < len;
i++,
tab_index++,
line++,
tmp_pos += 20
)
{
XmlNode materia = materias[0].ChildNodes[i];
Point label_position, textbox_position;
Label label = new Label();
TextBox textbox = new TextBox();
#if DEBUG_
if (line == 3)
{
label_X = 200 + tmp_pos;
label_Y = 25 + tmp_pos;
}
else
{
label_X += 10;
}
textbox_Y = label_Y;
#else
label_Y += 20;
textbox_Y = label_Y;
#endif
label.Text = "foo";
textbox.Size = new Size(48, 20);
textbox.Name = String.Format("nota{0}", fo.Name);
label_position = new Point();
label_position.X = label_X;
label_position.Y = label_Y;
textbox_position = new Point();
textbox_position.X = textbox_X;
textbox_position.Y = textbox_Y;
label.Location = label_position;
textbox.Location = textbox_position;
textbox.Left = 150;
textbox.TabIndex = tab_index;
notas_panel.Controls.Add(label);
notas_panel.Controls.Add(textbox);
}
我希望这很清楚。提前致谢