none
Multi-Monitor Programming WPF RRS feed

  • Question

  • Hi,


    I'm currently working with a WPF application on a multi-monitor system.  We need to ensure that the each window is visible on only a specific display.

     

    Is there an alternative to System.WinForms.Screen for determining monitor information in WPF? If so could you point me in the direction of which class?

     

    Assuming there isn't - how do the Screen.Bounds properties from WinForms relate to the Window.Top/Left properties in WPF.  I don't want to assign the entire application to just one monitor - so it needs to be done on a window-by-window basis.

     

    If I do something like:

     

    this.Left = Screen.AllScreens[1].Bounds.X;

    this.Top = Screen.AllScreens[1].Bounds.Y;

     

    I end up with the window ending up about -200 pixels off the 2nd monitor and about 100 pixels down... I would have expected it to end up at top left corner of the 2nd monitor as if I swap AllScreens[1] for index 0 it ends up where I'd expect it, top left corner of main monitor.

     

    If I need some kind of conversion between Bounds/Pixels/Crazy WPF location then - again - a couple of sample lines or a point in the direction of the right classes would be great Smile

     

    Thanks,

     

    Guy Powell

    Friday, December 7, 2007 10:13 PM

Answers

  • i don't know of any Screen collection type thing in WPF.  there are things in SystemParameters (e.g., WorkArea*, FullPrimaryScreen*, PrimaryScreen*, VirtualScreen*) which give you some information, but not about N screens. interop'ing to WinForms is probably the best bet.

    as far as the size, are you running in a high-DPI mode?  if so, you'd have to convert from pixels (which is what WinForms.Screen.Bounds gives you) to device-independent units.  that might be the source of your offset.

    see the end of http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2263219&SiteID=1 for a helper function.
    Friday, December 7, 2007 11:27 PM

All replies

  • i don't know of any Screen collection type thing in WPF.  there are things in SystemParameters (e.g., WorkArea*, FullPrimaryScreen*, PrimaryScreen*, VirtualScreen*) which give you some information, but not about N screens. interop'ing to WinForms is probably the best bet.

    as far as the size, are you running in a high-DPI mode?  if so, you'd have to convert from pixels (which is what WinForms.Screen.Bounds gives you) to device-independent units.  that might be the source of your offset.

    see the end of http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2263219&SiteID=1 for a helper function.
    Friday, December 7, 2007 11:27 PM
  • I am indeed running high-DPI and had managed to forget I even had it turned on :-)

     

    Thanks for that and should be problem solved once converted :-)

     

    Regards,

     

    Guy Powell

    Monday, December 10, 2007 7:39 PM