Example #1
0
        public ScreenInformation GetPrimaryScreen()
        {
            var screen = Screen.PrimaryScreen;

            var devicePosition = new Vector(
                screen.WorkingArea.X,
                screen.WorkingArea.Y);

            var deviceSize = new Vector(
                screen.WorkingArea.Width,
                screen.WorkingArea.Height);

            var deviceIndependentPosition = pixelConversionService
                                            .ConvertDeviceToDeviceIndependentPixels(devicePosition);

            var deviceIndependentSize = pixelConversionService
                                        .ConvertDeviceToDeviceIndependentPixels(deviceSize);

            return(new ScreenInformation(
                       deviceIndependentPosition,
                       deviceIndependentSize));
        }
Example #2
0
        public ScreenInformation GetActiveScreen()
        {
            var screens = Screen
                          .AllScreens
                          .Select(GetScreenInformationFromScreen)
                          .ToArray();

            var deviceMousePosition            = Control.MousePosition;
            var deviceIndependentMousePosition = pixelConversionService
                                                 .ConvertDeviceToDeviceIndependentPixels(
                new Vector(
                    deviceMousePosition.X,
                    deviceMousePosition.Y));

            var activeScreen = screens.First(screen =>
                                             screen.Bounds.X <= deviceIndependentMousePosition.X &&
                                             screen.Bounds.Y <= deviceIndependentMousePosition.Y &&
                                             screen.Bounds.X + screen.Bounds.Width >= deviceIndependentMousePosition.X &&
                                             screen.Bounds.Y + screen.Bounds.Height >= deviceIndependentMousePosition.Y);

            return(activeScreen);
        }