I want to position Form on top left corner of the screen.
I have tried this.Location = new Point(0,0)
but window is positioned at (7,0) - top of the window is on top of the screen but left side is 7 pixels from the screen edge.
I created new WinForms app for testing and added only this code:
private void Form1_Load(object sender, EventArgs e)
{
Point p = new Point(0, 0);
WindowState = FormWindowState.Maximized;
Debug.WriteLine("\nMaximized");
Debug.WriteLine("Location: " + Location);
Debug.WriteLine("Size: " + Size);
Debug.WriteLine("PointToScreen(0,0): " + PointToScreen(p));
WindowState = FormWindowState.Normal;
Location = p;
Debug.WriteLine("\nNormal");
Debug.WriteLine("Location: " + Location);
Debug.WriteLine("Size: " + Size);
Debug.WriteLine("PointToScreen(0,0): " + PointToScreen(p));
Debug.Write("\nScreen.PrimaryScreen.WorkingArea: ");
Debug.WriteLine(Screen.PrimaryScreen.WorkingArea);
}
The output is:
Maximized
Location: {X=-8,Y=-8}
Size: {Width=1936, Height=1056}
PointToScreen(0,0): {X=0,Y=23}
Normal
Location: {X=0,Y=0}
Size: {Width=300, Height=300}
PointToScreen(0,0): {X=8,Y=31}
Screen.PrimaryScreen.WorkingArea: {X=0,Y=0,Width=1920,Height=1040}
Why Location = new Point(0,0)
doesn't position form on (0,0)?
Is this due to something on my system? I have Win10 and VS2015. Taskbar is on the bottom, there is nothing on the left side of my desktop.
In order to position it on (0,0) I actually have to position it on (-7,0). Also, reported width of the maximized form is 16 pixels larger than screen width. I understand that because of window edges, title bar etc there is a difference between client area size and form size, but this is not it. When the form is maximized there are no left and right edges (client area width = desktop width) but form width is +16px. There is +8px on each of the 4 sides of the form but Y position is OK. Why is Y-position OK and X is not?