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 );
@Matheusmiranda can use
if (Screen.AllScreens.length > 1) { ... }
, so you’ll know if you have a project or other screen– Guilherme Nascimento