Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Position winform in the bottom left corner of the screen

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:

[Demo Screen](http://i.stack.imgur.com/9mTjj.png)

like image 588
user1559618 Avatar asked Sep 09 '12 10:09

user1559618


People also ask

How to specify where a form is displayed on the screen?

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 ’

How do you calculate the position of a form on screen?

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.

How do I set the console window position in C?

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.

Where is the top 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.


Video Answer


2 Answers

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;
like image 112
Ria Avatar answered Nov 15 '22 15:11

Ria


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.

like image 34
Manoj Avatar answered Nov 15 '22 14:11

Manoj