[C#] 在指定螢幕顯示視窗
首先要引入命名空間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;
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;
}
頁:
[1]