1

I want to get the Location of the right bottom corner to place a window above the traybar in Winforms that is at the same place using any desktop resolution.

I know that there are SystemParameters that give me the maximum height and width but I dont know how to get the window into the right bottom corner.

Quantum
  • 23
  • 7

1 Answers1

2

Set the StartPosition of the form to Manual and then set (in designer), then on load (this.Load += new System.EventHandler(this.Form_Load);) set this.Left and this.Top to requested values. (Left = 0 for primary screen left side, Top value calculate from screen resolution, window size (this.Size))

Sample code (your code):

private void Form_Load(object sender, EventArgs e)
{
  Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;
  // use 'Screen.AllScreens[1].WorkingArea' for secondary screen
  this.Left = workingArea.Left + workingArea.Width - this.Size.Width;
  this.Top = workingArea.Top + workingArea.Height - this.Size.Height;
}

(from designer; Form.Designer.cs)

  this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
  this.Text = "Form title";
  this.Load += new System.EventHandler(this.Form_Load);
Julo
  • 1,102
  • 1
  • 11
  • 19
  • The calculate part is the most important part for me because I want to have the Location of the windows straight above the Traybar and X and Y begins (/0 is) at the left upper corner and not on the right bottom/lower corner. – Quantum Mar 22 '18 at 13:21
  • Sorry, but I do not have the code for C# to get *current display work area*. This part is the simple part. The work area of current display is something I have coded long time ago and only in C++. I do not have the code on hand and therefore you need to figure it out yourself, e.g. https://stackoverflow.com/questions/1317235/c-get-complete-desktop-size or https://msdn.microsoft.com/en-us/library/system.windows.forms.screen.workingarea(v=vs.110).aspx – Julo Mar 22 '18 at 13:27
  • @Quantum : Answer was updated. It seems in C# it is more simple than it was in C++ *(perhaps it is because I use only a __primary screen__ and ignore the application starting screen)*. But do not forget, that this application moved the window to Right bottom corner and not to the tray bar. – Julo Mar 22 '18 at 13:43
  • For primary screen it should be zero in standard configuration *( <0,0> should be top left corner of primary screen)*. But when the user sets the task bar to left, then the working area may start at a different position than 0 (left). – Julo Mar 22 '18 at 14:00
  • I've found out a good way myself but thanks for your help. Your .Left and .Top-Ideas helped me :) – Quantum Mar 22 '18 at 15:02