How to design window2 on the secondary wpf screen?

0

Follow the code (MainWindow):

using System.Windows.Forms;
using System.Drawing;

var win2 = new SegundaTela();
Screen s2 = Screen.AllScreens[1];
Rectangle r2 = s2.WorkingArea;
win2.Top = r2.Top;
win2.Left = r2.Left;
win2.Show();

It is showing on the primary screen and not secondary. Any solution?

I've already asked a question with winforms here: How to project an image on the big screen?

    
asked by anonymous 11.12.2017 / 19:22

1 answer

2

Maybe Screen.AllScreens[1] is catching the first screen instead of the second, could try Screen.AllScreens[0] , or do exactly like @vnbrs response, but instead of using DeviceName would use Primary

Screen tela2 = Screen.AllScreens.FirstOrDefault(f => !f.Primary );

An idea, which I'm not sure, would be to check which monitor is running its main Form and then get the DeviceName , using # Screen.FromHandle , supposing that it is within the class would apply this , library_details.screen.fromhandle (v = vs.110) .aspx " following the suggestion of @MatheusMiranda , you may want to pass Window:

Screen principal = Screen.FromHandle(new WindowInteropHelper(this).Handle);
string nomedispositivo = principal.DeviceName;

Maybe you'll pass an element inside the Window, it would look like this with Screen.FromControl :

Screen principal = Screen.FromControl(<form vai aqui>);
string nomedispositivo = principal.DeviceName;

Then to get to the other screen would do this:

Screen tela2 = Screen.AllScreens.FirstOrDefault(f => f.DeviceName != nomedispositivo );
    
11.12.2017 / 19:56