【发布时间】:2018-08-31 21:57:30
【问题描述】:
我想获取右下角的位置,以便在 Winforms 中的托盘栏上方放置一个窗口,该窗口使用任何桌面分辨率位于同一位置。
我知道有 SystemParameters 可以为我提供最大高度和宽度,但我不知道如何让窗口进入右下角。
【问题讨论】:
标签: c# winforms location window
我想获取右下角的位置,以便在 Winforms 中的托盘栏上方放置一个窗口,该窗口使用任何桌面分辨率位于同一位置。
我知道有 SystemParameters 可以为我提供最大高度和宽度,但我不知道如何让窗口进入右下角。
【问题讨论】:
标签: c# winforms location window
将表单的StartPosition设置为Manual,然后设置(在设计器中),然后加载 (this.Load += new System.EventHandler(this.Form_Load);) em> 将 this.Left 和 this.Top 设置为请求的值。 (Left = 0 主屏幕左侧,Top 值根据屏幕分辨率、窗口大小计算 (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);
【讨论】: