我試圖在運行時添加標籤,當您單擊按鈕, 這是我的代碼,但是當您單擊按鈕時,它只是添加新標籤在新的位置和標籤之前通過點擊該按鈕沒有顯示 ,我想要顯示所有的人後點擊按鈕 我怎麼能解決它?通過單擊運行時按鈕創建控件在c#
Label lbl;
int number;
int locationX = 2;
int locationY = 4;
public void CreateRuntimeControl(PictureBox pic)
{
lbl; = new Label();
number++;
locationX++;
locationY++;
lbl.Name = "lbl" + number.ToString();
lbl.Size = new System.Drawing.Size(100, 50);
lbl.Location = new System.Drawing.Point(10 + locationX, 10 + locationY);
lbl.Text = number.ToString();
lbl.BackColor = Color.Gray;
pic.Controls.Add(lbl);
}
問候
您正在設置您的x和y座標,每個標籤有1個像素不同,因此它們彼此重疊。嘗試LocationY + = 50; –