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:
You can specify where a form is to be displayed on the computer screen by entering values in the Location property. You can set position, in pixels, of the top-left corner of the form. Also, you need to set the StartPosition property to indicate the boundaries of the display area. The default start position is ‘ WindowsDefaultLocation ’
Absolute Position b. Relative Position on Screen It simply subtracts the width of the form from the width of the screen and places the left side of the form in the calculated position. But be aware that the screen height value does refer to the whole screen, so you will find that the bottom of your form is hidden behind the Windows Taskbar.
Console.SetWindowPosition (Int32, Int32) Method in C# is used to set the position of the console window relative to the screen buffer. left: It is the column position of the upper left corner of the console window.
top: It is the row position of the upper left corner of the console window. ArgumentOutOfRangeException: When left or top is less than 0 or left + WindowWidth > BufferWidth or top + Windowheight > BufferHeight.
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;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With