How to project window2 on the secondary wpf screen?

Asked

Viewed 119 times

0

Following is 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. Some solution ?

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

1 answer

2

Maybe the Screen.AllScreens[1] is picking up the first screen instead of the second, could try Screen.AllScreens[0], or do exactly similar to reply from @vnbrs, but instead of using DeviceName would use the Primary

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

One idea, which I’m not sure of, would be to check which monitor is running its main form and then take the DeviceName, using Screen.FromHandle, Assuming you are inside the class would apply the this, following the suggestion of @Matheusmiranda, chance want to pass the Window:

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

If you were to pass an element inside the Window, it would be so with Screen.FromControl:

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

So to get the other screen would do this:

Screen tela2 = Screen.AllScreens.FirstOrDefault(f => f.DeviceName != nomedispositivo );
  • 1

    @Matheusmiranda can use if (Screen.AllScreens.length > 1) { ... }, so you’ll know if you have a project or other screen

Browser other questions tagged

You are not signed in. Login or sign up in order to post.