I have a Windows Forms application that I use the following code to dock it to the lower-right side of the screen when it is launched:
protected override void OnLoad(EventArgs e)
{
var s = Screen.FromPoint(this.Location);
this.Location = new Point(s.WorkingArea.Right - this.Width,
s.WorkingArea.Height - this.Height);
base.OnLoad(e);
}
When I am in Visual Studio debug mode, this works like a charm. When I build an installer and install the application (on the same dev box) and run it, the coordinates are slightly different and the form is not perfectly docked in the corner. So I stuck this in the OnLoad:
MessageBox.Show(this.Location.X + "x" + this.Location.Y);
In development mode it displays 1355x720 but when I install it displays 1365x730
Why the discrepency? Obviously I could just subtract 10 for my code to work but I would like an explanation for this behavior.
Update:
- This machine is Windows 8.1 Pro 64-bit with multiple monitors.
- It is the form size that is different (not
Screen.WorkingArea
). In development mode the form size shows 245x140 but when I install it shows 235x130 - I am also unable to give the form focus. There is a textbox on the form that receives focus onload. It has the blinking caret, but I cannot type until I physically click on the textbox. This again only happens when I install it; works fine when run from VS. I suspect this is related to the form position going off the screen edge.
- The form has
TopMost
set to True