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?
Asked
Active
Viewed 3.3k times
5 Answers
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
-
1Or `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));

Anonymous Helper
- 31
- 2
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);

Bill Tür stands with Ukraine
- 3,425
- 30
- 38
- 48