Reputation: 33
How can I get the current screen resolution of the screen where my form is?
I've already tried with primaryScreen but it does not work all times.
this.Size = new Size(Math.Min(width + 19, Screen.PrimaryScreen.WorkingArea.Width), Math.Min(height + dgvActualizar.ColumnHeadersHeight + 40, Screen.PrimaryScreen.WorkingArea.Height));
Upvotes: 2
Views: 2880
Reputation: 3377
See the following documentation for Screen class:
http://msdn.microsoft.com/en-us/library/e8xzhd15.aspx
Screen current = Screen.FromControl(this);
Rectangle area = current.WorkingArea;
You can then get
area.Width
and
area.Height.
Upvotes: 3
Reputation: 48686
You are probably looking for the FromControl
method:
Screen screenFormIsOn = Screen.FromControl(this);
var width = screenFormIsOn.WorkingArea.Width;
var height = screenFormIsOn.WorkingArea.Height;
Screen.FromControl
should return the screen in which your form is loaded on.
Upvotes: 6