在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的初学者......谢谢!
1 回答
您的面板高度是固定的 . 您的控件将添加到面板中 . 然而,由于面板高度,它们被隐藏在面板中 . 您可以增加面板高度或在面板/窗体中放置垂直滚动以使标签可见 .
还可以根据编号定义Y位置 . 标签