如何在C#Windows窗体中的特定位置定位开放表单?

表单中的Location属性设置为0,0(属性窗口)。 但是,表单不会在指定位置打开。 我错过了什么吗?

您需要将StartPosition设置为manual以使表单设置起始位置为Location Property中的值。

 public Form1() { InitializeComponent(); this.StartPosition = FormStartPosition.Manual; this.Location = new Point(0, 0); } 

FormStartPosition.Manual Intelisense摘要

FormStartPosition FormStartPosition.Manual

窗体的位置由System.Windows.Forms.Control.Location属性确定

默认情况下,开始位置设置为WindowsDefaultLocation,这将导致表单忽略您正在设置的位置。 要轻松强制设置位置,请将StartPosition更改为Manual。

StartPosition属性图片

尝试:

 this.Location = new Point(Screen.PrimaryScreen.Bounds.X, //should be (0,0) Screen.PrimaryScreen.Bounds.Y); this.TopMost = true; this.StartPosition = FormStartPosition.Manual; 

如果您忘记将StartPosition设置为FormStartPosition.Manual,则将位置设置为0,0无效

使用此属性可以在运行时显示表单的起始位置。 可以通过设置Location属性或使用Windows指定的默认位置手动指定表单的位置。 您还可以将表单放置在屏幕中央或其父表单的中心,以显示多文档界面(MDI)子表单等表单。