C# 使用最大化窗口时,如何更改标签的位置

C# 使用最大化窗口时,如何更改标签的位置,c#,C#,我有一个具有属性的label1(show1值) this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(554, 636); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(140, 155); this.label1.TextAlign = System.Draw

我有一个具有属性的label1(show1值)

    this.label1.AutoSize = true;
    this.label1.Location = new System.Drawing.Point(554, 636);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(140, 155);
    this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; 
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
//this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
在主窗体中添加以下代码

this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
//this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
它工作得很好。但是,如果我再添加一个代码作为

this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
//this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
我想自动更改标签1的位置,例如它仍然位于黄色区域。在C#中可能吗

this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
//this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

在visual studio中,默认情况下标签定位在顶部和左侧。当您最大化表单时,这会导致问题

this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
//this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
试试这行代码

this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
//this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.label1.Anchor = AnchorStyles.None;
另一种方法(来自Designer)

this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
//this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
单击标签,然后按F4,属性窗口将出现。 请参见锚定属性。
您可以将其更改为
NONE
。这将解决您的问题。

您必须使用该控件的锚定。在属性窗口中查找
锚定。
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
//this.WindowState = System.Windows.Forms.FormWindowState.Maximized;