■ 듀얼 모니터에서 보조 화면 윈도우를 여는 방법을 보여준다.
▶ MainWindow.xaml.cs
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); this.openButton.Click += openButton_Click; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 듀얼 모니터 보조 화면 창 열기 버튼 클릭시 처리하기 - openButton_Click(sender, e) /// <summary> /// 듀얼 모니터 보조 화면 창 열기 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void openButton_Click(object sender, RoutedEventArgs e) { System.Drawing.Rectangle rectangle = System.Windows.Forms.Screen.AllScreens[1].WorkingArea; Window window = new Window(); window.Left = rectangle.Left; window.Top = rectangle.Top; window.Width = rectangle.Width; window.Height = rectangle.Height; window.WindowStartupLocation = WindowStartupLocation.Manual; window.WindowState = WindowState.Normal; window.WindowStyle = WindowStyle.None; window.Topmost = true; window.Owner = this; window.FontFamily = new FontFamily("나눔고딕코딩"); window.FontSize = 16; Grid grid = new Grid(); window.Content = grid; Button closeButton = new Button(); closeButton.HorizontalAlignment = HorizontalAlignment.Center; closeButton.VerticalAlignment = VerticalAlignment.Center; closeButton.Width = 100; closeButton.Height = 30; closeButton.Content = "닫기"; closeButton.Click += closeButton_Click; grid.Children.Add(closeButton); window.Show(); window.WindowState = WindowState.Maximized; } #endregion #region 닫기 버튼 클릭시 처리하기 - closeButton_Click(sender, e) /// <summary> /// 닫기 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void closeButton_Click(object sender, RoutedEventArgs e) { Button button = sender as Button; ((button.Parent as Grid).Parent as Window).Close(); } #endregion } } |