如何设置辅助显示WPF窗口位置 [英] How to set WPF window position in secondary display

查看:306
本文介绍了如何设置辅助显示WPF窗口位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个显示器。我希望做一个媒体播放器,我想播放视频全屏我的副显示屏上。所以我试图让使用WPF

I have two displays. I want to make a media player and I want to play video full screen on my secondary display. So I’m trying to make a media player using WPF

下面是到目前为止的代码我写了

Here is the code so far I wrote

Screen[] _screens = Screen.AllScreens;
System.Drawing.Rectangle ractagle = _screens[1].Bounds;
//player is  my window
player.WindowState = WindowState.Maximized;
player.WindowStyle = WindowStyle.None;

player.Left = ractagle.X;
player.Top = ractagle.Y;


// MediaControl is an media elements
MediaControl.Height = ractagle.Height;
MediaControl.Width = ractagle.Width;



但不知何故,它只是打我的第一个显示器上。
任何形式的帮助是非常赞赏。

But somehow it’s just playing on my first display. Any kind of help is very much appreciated.

推荐答案

您需要确保该 WindowStartupLocation 设置为手动为您显示格式为:

You need to make sure that the WindowStartupLocation is set to Manual for the form you are displaying

否则什么都做得将对窗口的位置有任何影响。

Otherwise nothing you do will have any effect on the position of the window.

using System.Windows.Forms;
// reference System.Drawing
//

Screen s = Screen.AllScreens()[1];

System.Drawing.Rectangle r  = s.WorkingArea();
Me.Top = r.Top;
Me.Left = r.Left;

这头我使用的窗口的XAML的。

This header of the XAML of the Window I used.

<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="823" WindowStartupLocation="Manual">
    <Canvas Width="743">
        //Controls etc
    </Canvas>
</Window>

这篇关于如何设置辅助显示WPF窗口位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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