How do I know if the screen is in "Extend" mode?

4

I want to make a if to know if the screen is in "Extend" mode.

Example: (Win + P)

HowcanIdothisinC#:

if(?)//sópodeentrarnoif,seatelaestánomodo"Estender".
{
    SegundaTela formulario = new SegundaTela();
    Screen[] telas = Screen.AllScreens;
    Rectangle bounds = telas[1].Bounds; // pode ser outro índice.
    formulario.SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height);
    formulario.StartPosition = FormStartPosition.Manual;
    formulario.Show();
}
    
asked by anonymous 19.10.2017 / 22:23

2 answers

6

Just check if there is more than Screen :

if (Screen.AllScreens.Length > 1)
{
 //Estendido
}
else
{
 //Duplicado, ou apenas 1 tela
}
  

You did not specify, but this code is for winforms because the Screen class is derived from System.Windows.Forms

    
19.10.2017 / 23:16
3

I do not know something ready in .NET to use the "Extend" of Windows. You may be able to do this with the Windows API . / p>

In Windows 7, Windows 8 and 10 you can use System DisplaySwitch.exe with the /extend argument. For other versions of the system you will have to test. I do not know if Win + P was already shortcut in Vista.

var processo = new Process { StartInfo = { FileName = "DisplaySwitch.exe", Arguments = "/extend" } };
processo.Start();

In addition to /extend , there are other forms of presentation. You can use them with the arguments:

  • /external : only the second screen;
  • /internal : only the computer screen;
  • /clone : duplicates the screens.
19.10.2017 / 23:07