wpf需要在分屏上显示窗体代码:
<Window x:Class="WpfApp1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApp1" xmlns:vlc="clr-namespace:Vlc.DotNet.Wpf;assembly=Vlc.DotNet.Wpf" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Grid> <vlc:VlcControl x:Name="vlcControl" Loaded="vlcControl_Loaded" MouseMove="vlcControl_MouseMove"/> </Grid> </Window>
需要在分屏显示的窗体后台代码
#region 分屏显示 this.Loaded += (s, e) => { foreach (Screen scr in Screen.AllScreens) { if (!scr.Primary) { LogHelper.WriteLog(GetType(), "进入Screen"); //设置窗体位置 WindowStartupLocation = WindowStartupLocation.Manual; Left = scr.WorkingArea.Left; Top = scr.WorkingArea.Top; WindowState = WindowState.Maximized; break; } } }; #endregion
实现原理
假设屏幕分辨率是1920*1080,有两屏幕,多屏的情况下主屏的左上角的坐标为(0,0),第二个屏幕左上角坐标是(1920,0)。双屏显示就是让窗体自动偏移到指定的屏幕中。
例如:
Left = scr.WorkingArea.Left;
Top = scr.WorkingArea.Top;
注意事项
需要特别注意:Window.WindowState属性的设置,如果在Xaml代码中直接设置最大化,那么无论后续如何设置分屏窗口都会直接显示在主屏幕中。
转载:http://t.zoukankan.com/fishpond816-p-14292841.html
标签:WorkingArea,显示,多屏,Left,Top,窗体,wpf,分屏,scr From: https://www.cnblogs.com/lydj/p/17040123.html