表格位置在屏幕右下角
Posted
技术标签:
【中文标题】表格位置在屏幕右下角【英文标题】:Form position on lower right corner of the screen 【发布时间】:2013-02-17 19:06:37 【问题描述】:我正在使用 c# WinForm 开发一个 sman 通知应用程序。我想把主窗体放在屏幕工作区的右下角。 在多个屏幕的情况下,有一种方法可以找到最右边的屏幕来放置应用程序,或者至少记住最后使用的屏幕并将表单放在其右下角?
【问题讨论】:
相关帖子 - Place WinForm On Bottom-Right 【参考方案1】:我目前没有要检查的多个显示器,但应该是这样的
public partial class LowerRightForm : Form
public LowerRightForm()
InitializeComponent();
protected override void OnLoad(EventArgs e)
PlaceLowerRight();
base.OnLoad(e);
private void PlaceLowerRight()
//Determine "rightmost" screen
Screen rightmost = Screen.AllScreens[0];
foreach (Screen screen in Screen.AllScreens)
if (screen.WorkingArea.Right > rightmost.WorkingArea.Right)
rightmost = screen;
this.Left = rightmost.WorkingArea.Right - this.Width;
this.Top = rightmost.WorkingArea.Bottom - this.Height;
【讨论】:
或var rightmost = Screen.AllScreens.OrderBy (s => s.WorkingArea.Right).Last();
@GertArnold 我知道 MoreLINQ 的 MaxBy
效率最高,但如果我不得不冒险猜测 OrderByDescending.First
应该比 OrderBy.Last
更有效。【参考方案2】:
覆盖表单Onload
并设置新位置:
protected override void OnLoad(EventArgs e)
var screen = Screen.FromPoint(this.Location);
this.Location = new Point(screen.WorkingArea.Right - this.Width, screen.WorkingArea.Bottom - this.Height);
base.OnLoad(e);
【讨论】:
【参考方案3】://Get screen resolution
Rectangle res = Screen.PrimaryScreen.Bounds;
// Calculate location (etc. 1366 Width - form size...)
this.Location = new Point(res.Width - Size.Width, res.Height - Size.Height);
【讨论】:
【参考方案4】:以下代码应该可以工作:)
var rec = Screen.PrimaryScreen.WorkingArea;
int margain = 10;
this.Location = new Point(rec.Width - (this.Width + margain), rec.Height - (this.Height + margain));
【讨论】:
【参考方案5】: int x = Screen.PrimaryScreen.WorkingArea.Right - this.Width;
int y = Screen.PrimaryScreen.WorkingArea.Bottom - this.Height;
// Add this for the real edge of the screen:
x = 0; // for Left Border or Get the screen Dimension to set it on the Right
this.Location = new Point(x, y);
【讨论】:
以上是关于表格位置在屏幕右下角的主要内容,如果未能解决你的问题,请参考以下文章
c# 弹出窗,要求在指定位置弹出窗体(屏幕正中、屏幕右下角)