如何获得活动屏幕尺寸? [英] How can I get the active screen dimensions?

查看:29
本文介绍了如何获得活动屏幕尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找的是相当于窗口当前所在监视器的 System.Windows.SystemParameters.WorkArea.

What I am looking for is the equivalent of System.Windows.SystemParameters.WorkArea for the monitor that the window is currently on.

澄清:有问题的窗口是WPF,而不是WinForm.

Clarification: The window in question is WPF, not WinForm.

推荐答案

Screen.FromControlScreen.FromPointScreen.FromRectangle 应该帮你解决这个问题.例如在 WinForms 中,它将是:

Screen.FromControl, Screen.FromPoint and Screen.FromRectangle should help you with this. For example in WinForms it would be:

class MyForm : Form
{
  public Rectangle GetScreen()
  {
    return Screen.FromControl(this).Bounds;
  }
}

我不知道对 WPF 的等效调用.因此,你需要做一些类似这种扩展方法的事情.

I don't know of an equivalent call for WPF. Therefore, you need to do something like this extension method.

static class ExtensionsForWPF
{
  public static System.Windows.Forms.Screen GetScreen(this Window window)
  {
    return System.Windows.Forms.Screen.FromHandle(new WindowInteropHelper(window).Handle);
  }
}

这篇关于如何获得活动屏幕尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆