1
我想創建一個標籤並將其顯示給用戶,但我不能。通過代碼創建並顯示標籤
我試圖將代碼複製中的InitializeComponent()的任何標籤...
(我使用工具箱中添加一個標籤到Form1。)
partial class Form1
{
private System.Windows.Forms.Label label1;
private void InitializeComponent()
{
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(0, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
}
}
...和然後將其應用於我的標籤。
(我刪除我之前添加的標籤。)
public partial class Form1 : Form
{
private Label label;
public Form1()
{
InitializeComponent();
label = new Label();
label.AutoSize = true;
label.Location = new System.Drawing.Point(0, 0);
label.Name = "label";
label.Size = new System.Drawing.Size(0, 0);
label.TabIndex = 0;
label.Text = "Test";
//label.Enabled = true;
label.Visible = true;
//label.Select();
//label.Show();
}
}
但它不工作。 怎麼辦?
你還沒有添加標籤的形式或其他家長,將允許它被顯示。 –