I'm trying to open a new WPF Window in a second monitor from a Windows located in the primary monitor. Following what I founded in other threads and discussions I wrote this:
System.Windows.Forms.Screen s1 = System.Windows.Forms.Screen.AllScreens[1];
System.Drawing.Rectangle r1 = s1.WorkingArea;
form.WindowState = System.Windows.WindowState.Normal;
form.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
form.Top = r1.Top;
form.Left = r1.Left;
form.Show();
form.WindowState = System.Windows.WindowState.Maximized;
but this code not work: the new window is shown in the primary monitor. How I can resolve this problem? Thanks.
CodePudding user response:
The solution was to use r.X and r.Y instead of r.top and r.left:
System.Windows.Forms.Screen s1 = System.Windows.Forms.Screen.AllScreens[1];
System.Drawing.Rectangle r1 = s1.WorkingArea;
form.WindowState = System.Windows.WindowState.Normal;
form.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
form.Top = r1.Y;
form.Left = r1.X;
form.Show();
form.WindowState = System.Windows.WindowState.Maximized;
now it works.