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

Asked

Viewed 400 times

4

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

Example: (Win + P)

inserir a descrição da imagem aqui

How can I do this in C#:

if (?) // só pode entrar no if, se a tela está no modo "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();
}
  • There is no way to do this just with . NET, you will need to call the Windows C++ API. But what is your goal with that? Maybe detecting screen mode is unnecessary, if all you want is something like projecting on a specific screen.

  • @Renan, I asked a question here: https://answall.com/questions/245514/como-projetar-uma-imagem-no-tel%C3%A3o of how to project the screen. That’s why I asked the question here to know if PC is in "Extend" mode, because if user does not choose the extend option, the second screen (form) will not show on the screen, for example.

  • Somehow I need to show a warning to activate in "Extend".

  • I think you can see the screen size, if it is extended, the second screen will not have x=0

  • It’s just a hunch... I’ll take a test

  • It would serve to force the "extend"?

  • Yes, it could be @vnbrs

Show 2 more comments

2 answers

6


Just check if there’s more than one Screen:

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

You didn’t specify, but this code is for winforms because the Screen class derives from System.Windows.Forms

  • Does that really work? I swore that the screen count was the same regardless of the mode, because even with screen replication, each one can have different resolution, area and bit depth.

  • 1

    I just tested it here, it surprised me because even though it’s in duplicate mode, the screen count becomes just one.

  • 1

    In this case +1, that’s genius.

  • 3

    WPF projects can use System.Windows.Forms without problems

  • 1

    It really works, LOOOOL

3

I don’t know anything about . NET to use Windows "Extend". Maybe you can do it with Windows API.

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

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

Beyond the /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: duplicate the screens.
  • After doing this you can force the application to appear on a specific monitor. BTW +1.

  • Gives error: System.ComponentModel.Win32exception: 'System cannot find specified file'

  • @vnbs ,Windows 10.

  • You’re talking about the DisplaySwitch.exe ?

  • 1

    @Renan not only the application, but all, because it modifies what is being used in the system as if to use Win + P

  • @vnbrs, I liked the idea of forcing to "Extend".

Show 1 more comment

Browser other questions tagged

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