11

I am using c# WinForm to develop a sman notification app. I would like to place the main form on the lower right corner of the screen working area. In case of multiple screens, there is a way to find the rightmost screen where to place the app, or at least remember the last used screen and palce the form on its lower right corner?

Terix
  • 1,367
  • 5
  • 25
  • 39
  • Related post - [Place WinForm On Bottom-Right](https://stackoverflow.com/q/1385674/465053) – RBT Nov 30 '21 at 10:27

5 Answers5

26

I don't currently have multiple displays to check, but it should be something like

    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;
        }
    }
David Goshadze
  • 1,439
  • 12
  • 16
  • 1
    Or `var rightmost = Screen.AllScreens.OrderBy (s => s.WorkingArea.Right).Last();` – Gert Arnold Mar 04 '13 at 08:33
  • @GertArnold I know MoreLINQ has `MaxBy` to be most efficient but if I have to hazard a guess `OrderByDescending.First` should be more efficient than `OrderBy.Last`. – nawfal Mar 02 '17 at 15:12
9

Override the Form Onload and set the new location :

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);
}
Sami Franka
  • 146
  • 3
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); 
Umut D.
  • 1,746
  • 23
  • 24
1

This following code should work :)

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

this.Location = new Point(rec.Width - (this.Width + margain), rec.Height - (this.Height + margain));
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);