如何设置窗口以覆盖虚拟屏幕区域?

时间:2012-04-23 20:20:27

标签: c# wpf window size dpi

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

1 个答案:

答案 0 :(得分: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;
}