c#中的当前屏幕分辨率

时间:2014-12-31 18:01:05

标签: c# winforms visual-studio

如何获取我的表单所在屏幕的当前屏幕分辨率?

我已经尝试过使用primaryScreen,但它不能一直工作。

this.Size = new Size(Math.Min(width + 19, Screen.PrimaryScreen.WorkingArea.Width), Math.Min(height + dgvActualizar.ColumnHeadersHeight + 40, Screen.PrimaryScreen.WorkingArea.Height));

2 个答案:

答案 0 :(得分:4)

您可能正在寻找FromControl方法:

Screen screenFormIsOn = Screen.FromControl(this);
var width = screenFormIsOn.WorkingArea.Width;
var height = screenFormIsOn.WorkingArea.Height;

Screen.FromControl应该返回加载表单的屏幕。

答案 1 :(得分:2)

请参阅屏幕类的以下文档:

http://msdn.microsoft.com/en-us/library/e8xzhd15.aspx

Screen current = Screen.FromControl(this);
Rectangle area = current.WorkingArea;

然后你可以

area.Width 

area.Height.
相关问题