如何在每个使用桌面分辨率(Winforms)的右下角放置一个window
How to put a window on the right bottom corner on every using the desktop resolution (Winforms)
我想获取右下角的位置,以便在 Winforms 中的托盘栏上方放置一个 window,这与使用任何桌面分辨率的位置相同。
我知道有系统参数给我最大高度和宽度,但我不知道如何让 window 进入右下角。
将表单的StartPosition
设置为Manual
然后设置(在设计器中),然后加载 (this.Load += new System.EventHandler(this.Form_Load);
) 将 this.Left
和 this.Top
设置为请求的值。 (Left = 0
对于主屏幕左侧,Top
值根据屏幕分辨率计算,window 大小 (this.Size
))
示例代码(您的代码):
private void Form_Load(object sender, EventArgs e)
{
Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;
// use 'Screen.AllScreens[1].WorkingArea' for secondary screen
this.Left = workingArea.Left + workingArea.Width - this.Size.Width;
this.Top = workingArea.Top + workingArea.Height - this.Size.Height;
}
(来自设计师;Form.Designer.cs)
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Form title";
this.Load += new System.EventHandler(this.Form_Load);
我想获取右下角的位置,以便在 Winforms 中的托盘栏上方放置一个 window,这与使用任何桌面分辨率的位置相同。
我知道有系统参数给我最大高度和宽度,但我不知道如何让 window 进入右下角。
将表单的StartPosition
设置为Manual
然后设置(在设计器中),然后加载 (this.Load += new System.EventHandler(this.Form_Load);
) 将 this.Left
和 this.Top
设置为请求的值。 (Left = 0
对于主屏幕左侧,Top
值根据屏幕分辨率计算,window 大小 (this.Size
))
示例代码(您的代码):
private void Form_Load(object sender, EventArgs e)
{
Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;
// use 'Screen.AllScreens[1].WorkingArea' for secondary screen
this.Left = workingArea.Left + workingArea.Width - this.Size.Width;
this.Top = workingArea.Top + workingArea.Height - this.Size.Height;
}
(来自设计师;Form.Designer.cs)
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Form title";
this.Load += new System.EventHandler(this.Form_Load);