【发布时间】:2015-04-12 18:24:14
【问题描述】:
在 WinForms 上,每次单击按钮时,我都会尝试将控件(此处为简单标签)添加到面板中。 用户界面如下所示:
当我第一次点击按钮时,我得到了这个(我所期望的!):
但是,在第二次、第三次等点击之后,什么也没有发生;不再添加任何标签:(
但是,当我处于调试模式时,我可以在控件列表中看到它们:
这是我的代码(只有有趣的东西):
public partial class GestionPateFeuilletee : Form
{
private List<Label> listeTours = new List<Label>();
public GestionPateFeuilletee()
{
InitializeComponent();
}
private void boutonAjouterTour_Click(object sender, EventArgs e)
{
Point coordDepart = new Point(10, 160);
int tabIndexDepart = 5;
listeTours.Add(new Label());
listeTours.Last().Name = "labelTour" + (listeTours.Count());
listeTours.Last().Location = new System.Drawing.Point(coordDepart.X, coordDepart.Y + 30);
listeTours.Last().TabIndex = tabIndexDepart + 1;
listeTours.Last().Text = "labelTour" + (listeTours.Count());
this.panelDescription.Controls.Add(listeTours.Last());
}
}
有什么想法吗? 是的,我是 WinForms 的初学者...... 谢谢!
【问题讨论】:
-
增加面板高度并检查
-
由于您将它们全部添加到同一点,它们是否有可能相互重叠?
-
笨蛋,就是这样:都在同一点上!关于高度,面板几乎占据了窗口的所有空间(默认情况下是屏幕截图的大小),所以我认为不是这样。