Reputation: 469
I am trying to position a form in the bottom left hand corner of the screen (on the start button) I have the following code that attempts to do this, but only takes into account the work area of the screen - so the form is positioned just above the start button:
int x = Screen.PrimaryScreen.WorkingArea.Left + this.Width;
int y = Screen.PrimaryScreen.WorkingArea.Bottom - this.Height;
this.Location = new Point(x, y);
A demo / screen is below to further demonstrate what I am trying to do:
Upvotes: 12
Views: 19555
Reputation: 2168
The Ria 's answer is correct but it didn't add the taskbar height.
If you want exactly what in the image shown , you should use this code :
int nTaskBarHeight = Screen.PrimaryScreen.Bounds.Bottom -
Screen.PrimaryScreen.WorkingArea.Bottom;
Rectangle workingArea = Screen.GetWorkingArea(this);
this.Location = new Point(0, workingArea.Bottom - Size.Height + nTaskBarHeight);
this.TopMost = true;
Upvotes: 0
Reputation: 5097
The Working area usually excludes any task bar, docked windows and docked tool bars.
Using the Screen.PrimaryScreen.Bounds
gives you the complete height and width of your screen.
A sample code is as follows :
public Form1()
{
InitializeComponent();
Rectangle r = Screen.PrimaryScreen.WorkingArea;
this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(0, Screen.PrimaryScreen.Bounds.Height - this.Height);
this.TopMost = true;
}
This most likely will show below the task bar as usually task bar is set to be on top by default. I remember there was an option to turn that option off in Windows XP, not sure though.
EDIT:
In windows XP you can make the taskbar go behind windows. Follow the link : Always on top task bar
As pointed by Ria, setting the this.TopMost
to true works and is a better option.
Upvotes: 4
Reputation: 10357
Use Screen.PrimaryScreen.Bounds
properties and set this.TopMost = true
. this works:
int y = Screen.PrimaryScreen.Bounds.Bottom - this.Height;
this.Location = new Point(0, y);
this.TopMost = true;
Upvotes: 11
Reputation: 29000
You can try with this code
Rectangle workingArea = Screen.GetWorkingArea(this);
this.Location = new Point(0,
workingArea.Bottom - Size.Height);
Upvotes: 0