需要引用:
using System.Windows.Forms;
using System.Drawing;
1 public partial class App : System.Windows.Application 2 { 3 protected override void OnStartup(StartupEventArgs e) 4 { 5 6 base.OnStartup(e); 7 MainWindow w1 = new MainWindow();//主窗口 8 RevealWindow w2 = new RevealWindow();//副窗口 9 if (Screen.AllScreens.Length > 1) 10 { 11 12 Screen s1 = Screen.AllScreens[0];//主屏幕 13 Screen s2 = Screen.AllScreens[1];//副屏幕 14 Rectangle r1 = s1.WorkingArea; 15 Rectangle r2 = s2.WorkingArea; 16 //因为我的主副屏幕是反的所以主窗口放入副屏幕中。
17 //主窗口放入副屏幕中 18 w1.Top = r2.Top; 19 w1.Left = r2.Left; 20 //副窗口放入主屏幕中 21 w2.Top = r1.Top; 22 w2.Left = r1.Left; 23 24 w1.Show(); 25 w2.Show(); 26 27 w2.Owner = w1; 28 } 29 } 30 }