11

我正在使用 c# WinForm 开发一个 sman 通知应用程序。我想把主窗体放在屏幕工作区的右下角。在多个屏幕的情况下,有一种方法可以找到最右边的屏幕来放置应用程序,或者至少记住最后使用的屏幕并将表单放在右下角?

4

5 回答 5

25

我目前没有要检查的多个显示器,但它应该类似于

    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;
        }
    }
于 2013-03-03T18:33:31.770 回答
9

覆盖表单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);
}
于 2013-03-03T18:24:24.707 回答
2
//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); 
于 2015-08-09T14:31:09.667 回答
1

以下代码应该可以工作:)

var rec = Screen.PrimaryScreen.WorkingArea;
int margain = 10;

this.Location = new Point(rec.Width - (this.Width + margain), rec.Height - (this.Height + margain));
于 2019-07-30T02:39:37.557 回答
0
    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);
于 2015-11-01T16:39:54.837 回答