Quantum
Quantum

Reputation: 23

How to put a window on the right bottom corner on every using the desktop resolution (Winforms)

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.

Upvotes: 1

Views: 2248

Answers (1)

Julo
Julo

Reputation: 1120

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);

Upvotes: 2

Related Questions