博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WPF使用扩展屏幕
阅读量:5107 次
发布时间:2019-06-13

本文共 3254 字,大约阅读时间需要 10 分钟。

原文:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Forms;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;namespace ScreenShadow{    ///     /// MainWindow.xaml 的交互逻辑    ///     public partial class MainWindow : Window    {        public MainWindow()        {            InitializeComponent();        }        private void Button_Click(object sender, RoutedEventArgs e)        {            Window1 window = new Window1();            window.Show();        }        private void Button_Click_1(object sender, RoutedEventArgs e)        {            Window2 window = new Window2();            window.Show();        }        List
openWindows = new List
(); private void Button_Click_2(object sender, RoutedEventArgs e) { openWindows.Clear(); Screen[] screens = Screen.AllScreens; if (screens.Length == 1) { lblmsg.Content = "已经投射1个显示器"; } else if (screens.Length == 2) { lblmsg.Content = "已经投射2个显示器"; } else if (screens.Length == 4) { lblmsg.Content = "已经投射4个显示器"; } else { lblmsg.Content = "目前仅支持1,2,4个显示器模式"; } //主屏幕显示 Screen mainScreen = screens.FirstOrDefault(x=>x.Primary==true); //主屏幕显示window1 Window1 win1 = new Window1(); win1.WindowState = WindowState.Maximized; win1.WindowStartupLocation = WindowStartupLocation.Manual; System.Drawing.Rectangle mswa = mainScreen.WorkingArea; win1.Left = mswa.Left; win1.Top = mswa.Top; win1.Width = mswa.Width; win1.Height = mswa.Height; openWindows.Add(win1); win1.Show(); //其他屏幕显示,这里假设有2个 var subScreen = (from o in screens where o.Primary == false select o).ToList
(); if (subScreen.Count > 0) { var subscreen1 = subScreen[0]; Window2 win2 = new Window2(); win1.WindowState = WindowState.Maximized; win1.WindowStartupLocation = WindowStartupLocation.Manual; System.Drawing.Rectangle mswa2 = subscreen1.WorkingArea; win2.Left = mswa2.Left; win2.Top = mswa2.Top; win2.Width = mswa2.Width; win2.Height = mswa2.Height; openWindows.Add(win2); win2.Show(); } } private void BtnClose_Click(object sender, RoutedEventArgs e) { if (openWindows.Count > 0) { foreach (var item in openWindows) { item.Close(); } } } }}
View Code

 

posted on
2019-04-19 01:08 阅读(
...) 评论(
...)

转载于:https://www.cnblogs.com/lonelyxmas/p/10733590.html

你可能感兴趣的文章
一行代码解决各种IE兼容问题,IE6,IE7,IE8,IE9,IE10
查看>>
北京信息科技大学第十一届程序设计竞赛(重现赛)I
查看>>
【3-5】函数及递归
查看>>
转 Python的WinReg项通过子键循环
查看>>
二叉树思想
查看>>
SpringBoot入门(四)静态资源
查看>>
本机ping不通虚拟机,但虚拟机可以ping通本机时怎么解决
查看>>
2013-03-26 星期二
查看>>
Java基础篇——编码注释规范
查看>>
VMware下利用ubuntu13.04建立嵌入式开发环境之二
查看>>
Longest Palindromic Substring
查看>>
jQuery插件——Validation Plugin表单验证
查看>>
Web前端学习笔记:Bootstrap框架
查看>>
restrict和volatile的作用
查看>>
c# 枚举基础有[flags]和没有的的区别
查看>>
static关键字——读《嵌入式c语言进阶之道》整理
查看>>
html5 的localstorage
查看>>
项目日志的管理和应用 log4js-Node.js中的日志管理模块使用与封装
查看>>
linux通过端口号查找程序执行路径
查看>>
Java日期
查看>>