Getting Current Screen Size in WPF
Your question focuses on determining the size of the current screen in a multi-screen setup, where all screens may not use the same resolution. While you've mentioned using SystemParameters.PrimaryScreenWidth and SystemParameters.PrimaryScreenHeight for the primary screen, it's indeed essential to obtain the size of the current screen.
To address this, you can utilize WpfScreen, a wrapper class that encapsulates the Screen class from System.Windows.Forms. This class offers several methods to retrieve screen-related information:
Additionally, WpfScreen provides the following properties:
Example usage:
// Get the primary screen's size var primaryScreen = WpfScreen.Primary; Console.WriteLine("Primary Screen: {0} x {1}", primaryScreen.DeviceBounds.Width, primaryScreen.DeviceBounds.Height); // Get the current window's screen size var currentWindow = new Window(); // Replace this with the actual window object var currentScreen = WpfScreen.GetScreenFrom(currentWindow); Console.WriteLine("Current Window's Screen: {0} x {1}", currentScreen.DeviceBounds.Width, currentScreen.DeviceBounds.Height); // Get the screen containing a specified point var point = new Point(500, 300); var containingScreen = WpfScreen.GetScreenFrom(point); Console.WriteLine("Screen Containing Point: {0} x {1}", containingScreen.DeviceBounds.Width, containingScreen.DeviceBounds.Height);
The above is the detailed content of How to Get the Current Screen Size in WPF on a Multi-Screen Setup?. For more information, please follow other related articles on the PHP Chinese website!