- UID
- 390967
- 帖子
- 1582
- 主題
- 816
- 精華
- 0
- 積分
- 852
- 楓幣
- 10686
- 威望
- 393
- 存款
- 10100
- 贊助金額
- 1800
- 推廣
- 0
- GP
- 2662
- 閱讀權限
- 150
- 在線時間
- 188 小時
- 註冊時間
- 2023-5-18
- 最後登入
- 2024-11-16
|
首先要引入命名空間- using Screen = System.windows.Forms.Screen;
複製代碼 自訂一個方法用來處理在指定螢幕顯示的功能- void ShowOnMonitor(Window win, int monitorIndex)
- {
- int screenCount = Screen.AllScreens.Count();
- if (monitorIndex >= screenCount) monitorIndex = 0;
- Screen sc = Screen.AllScreens[monitorIndex];
- win.WindowStartupLocation = WindowStartupLocation.Manual;
- win.Top = sc.WorkingArea.Top;
- win.Left = sc.WorkingArea.Left;
- win.Width = sc.WorkingArea.Width;
- win.Height = sc.WorkingArea.Height;
- win.Loaded += Window_Loaded;
- }
複製代碼 在視窗的 Loaded 事件加入上面的方法- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- var senderWindow = sender as Window;
- if (null == senderWindow) return;
- senderWindow.WindowState = WindowState.Maximized;
- }
複製代碼 |
|