【问题标题】:How can I set my window to cover exactly the virtual screen area?如何设置我的窗口以完全覆盖虚拟屏幕区域?
【发布时间】:2012-04-23 20:20:26
【问题描述】:

我可以从 System.Windows.SystemParameters 获取虚拟屏幕大小,但由于 WPF 不能以像素为单位工作,但在 DPI 单位中我不能直接使用它。 如何让我的 WPF 窗口 (Border=none) 完全覆盖整个虚拟屏幕?

【问题讨论】:

  • 你能展示你目前拥有的代码吗(例如获取虚拟屏幕大小的代码等)?

标签: c# wpf window size dpi


【解决方案1】:

我这样做了,效果很好:

public MainWindow()
{
    InitializeComponent();

    this.WindowStyle = System.Windows.WindowStyle.None;

    this.Height = SystemParameters.VirtualScreenHeight;
    this.Width = SystemParameters.VirtualScreenWidth;

    this.Left = 0;
    this.Top = 0;
}

这是您的想法(但没有发布)吗?

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    this.WindowStyle = System.Windows.WindowStyle.None;

    this.Left = 0;
    this.Top = 0;

    Point screenPoint = new Point(SystemParameters.VirtualScreenWidth, SystemParameters.VirtualScreenHeight);

    Point translatedPoint = this.PointFromScreen(screenPoint);

    this.Height = translatedPoint.Y;
    this.Width = translatedPoint.X;
}

【讨论】:

  • 请记住,虚拟桌面不一定是矩形的。
猜你喜欢
  • 2013-08-24
  • 1970-01-01
  • 1970-01-01
  • 2014-06-29
  • 2019-10-27
  • 2021-03-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-18
相关资源
最近更新 更多