System.Windows.Forms.Screen
works fine in WPF, so I think that the WPF designers could not replace it with a WPF-specific version.
Of course, you will need to convert the coordinates. Here's an easy class to convert:
public class ScreenBoundsConverter { private Matrix _transform; public ScreenBoundsConverter(Visual visual) { _transform = PresentationSource.FromVisual(visual).CompositionTarget.TransformFromDevice; } public Rect ConvertBounds(Rectangle bounds) { var result = new Rect(bounds.X, bounds.Y, bounds.Width, bounds.Height); result.Transform(_transform); return result; } }
Usage example:
var converter = new ScreenBoundsConverter { Visual = this }; foreach(var screen in System.Windows.Forms.Screen.AllScreens) { Rect bounds = converter.ConvertBounds(screen.Bounds); ... }
Ray Burns Apr 14 '10 at 16:44 2010-04-14 16:44
source share