wpf2017.12.07 14:25

다중모니터에서 WindowState="Maximum"으로 하게 되면 한모니터에서만 나오게 된다.

이를 해결하기 위해서

 그냥 Window에 맞게 만들면 된다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
 
            var ratio = Math.Max(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width / SystemParameters.PrimaryScreenWidth,
                            System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height / SystemParameters.PrimaryScreenHeight);
 
            int monitorNumber = 1;
 
            int left = Convert.ToInt32(ConfigurationManager.AppSettings["MonitorLeft"]);
            int center = Convert.ToInt32(ConfigurationManager.AppSettings["MonitorCenter"]);
            int right = Convert.ToInt32(ConfigurationManager.AppSettings["MonitorRight"]);
 
            foreach (var screen in System.Windows.Forms.Screen.AllScreens)
            {
                if (monitorNumber == left)
                {
                    var window = new MainWindow();
                    ShowWindow(window, screen, ratio);
                }
                else if (monitorNumber == center)
                {
                    var videoWindow = new VideoWindow();
                    videoWindow.PlayVideo("did2");
                    ShowWindow(videoWindow, screen, ratio);
                }
                else if (monitorNumber == right)
                {
                    var videoWindow = new VideoWindow();
                    videoWindow.PlayVideo("did3");
                    ShowWindow(videoWindow, screen, ratio);
                }
                monitorNumber++;
            }
            Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
        }
 
        public void ShowWindow(Window window, System.Windows.Forms.Screen screen, double ratio)
        {
            window.Left = screen.WorkingArea.Left / ratio;
            window.Top = screen.WorkingArea.Top / ratio;
            window.Width = screen.WorkingArea.Width / ratio;
            window.Height = screen.WorkingArea.Height / ratio;
            window.Show();
            window.WindowState = WindowState.Maximized;
        }


중요한포인트는 screen.WorkingArea 이다. 여기서 각장 포지션에 맞게 지정하면 된다.

저작자 표시
신고
Posted by 동동(이재동)