How to design window2 on wpf secondary screen?



  • The following 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 and non-secondary screen. Any solutions?

    I've asked a question with winforms here: https://pt.stackoverflow.com/questions/245514/como-projetar-uma-imagem-no-tel%C3%A3o



  • Maybe Screen.AllScreens[1] be taking the first screen instead of the second one, could try Screen.AllScreens[0], or do exactly similar to https://pt.stackoverflow.com/a/245516/3635 , but instead of using DeviceName would use Primary

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

    An idea, of which I'm not sure, would check which monitor is running its main Form and then take the DeviceName, using https://msdn.microsoft.com/pt-br/library/system.windows.forms.screen.fromhandle(v=vs.110).aspx , assuming that it is within the class would apply the this, following the suggestion of the https://stackoverflow.com/a/10140768/1518921 , want to pass the Window:

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

    I'll pass an element inside the Window, so it would be https://msdn.microsoft.com/pt-br/library/system.windows.forms.screen.fromcontrol(v=vs.110).aspx :

    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 );
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2