• WPF使用扩展屏幕


    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
    {
        /// <summary>
        /// MainWindow.xaml 的交互逻辑
        /// </summary>
        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<Window> openWindows = new List<Window>();
            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<Screen>();
                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
  • 相关阅读:
    Windows 显示隐藏文件
    Python 程序一行代码解决乘法口诀表
    【转发】基于Bert-NER构建特定领域的中文信息抽取框架(上)
    【转发】GET和POST两种基本请求方法的区别
    【转发】实现yolo3模型训练自己的数据集总结
    第十章集合总结
    2016-2017 201671010134 异常处理
    JAVA基础编程
    2016-2017 201671010134 第六章总结
    java总结
  • 原文地址:https://www.cnblogs.com/fuchongjundream/p/4206259.html
Copyright © 2020-2023  润新知