【问题标题】:Current screen resolution in c#C#中的当前屏幕分辨率
【发布时间】:2015-01-01 02:35:07
【问题描述】:

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

我已经尝试过使用primaryScreen,但它并不总是有效。

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

【问题讨论】:

  • 怎么不行?如果没有,有什么问题?

标签: c# winforms visual-studio


【解决方案1】:

您可能正在寻找FromControl 方法:

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

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

【讨论】:

    【解决方案2】:

    有关 Screen 类,请参阅以下文档:

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

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

    你可以得到

    area.Width 
    

    area.Height.
    

    【讨论】:

    • 否决我的答案的人可以告诉我如何编辑/修改我的答案吗?谢谢。
    • 我不是投反对票的人,但您可以使用 `area.Width` 在同一行中键入变量名称
    • 对。我会做出这些改变。
    猜你喜欢
    • 2012-02-15
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    相关资源
    最近更新 更多