Подтвердить что ты не робот

Позиция формы в правом нижнем углу экрана

Я использую С# WinForm для разработки приложения уведомления SMAN. Я хотел бы разместить основную форму в правом нижнем углу рабочей области экрана. В случае нескольких экранов есть способ найти самый правый экран, на котором разместить приложение, или, по крайней мере, помнить последний использованный экран и закрепить форму в правом нижнем углу?

4b9b3361

Ответ 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;
        }
    }

Ответ 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);