public void CenterWindowOnScreen() { var screen = WpfScreen.GetScreenFrom(this).WorkingArea; Left = (screen.Width / 2) - (Width / 2); Top = (screen.Height / 2) - (Height / 2); }
protected WpfScreen GetScreenFromSide(Side side) { return (WpfScreen.GetScreenFrom(side == Side.Left ? new Point(WpfScreen.MostLeftX, 0) : new Point(WpfScreen.MostRightX, 0))); }
private void UpdateLimitations(WpfScreen screen, double scaleX, double scaleY) { SaveOriginalLimitations(); Logging.Debug($"{_originalMinSize.Width * scaleX}×{_originalMinSize.Height * scaleY} ({scaleX}, {scaleY}); {screen.WorkingArea}"); MaxWidth = _originalMaxSize.Width * (_originalMaxSize.Width < UnlimitedSize ? scaleX : 1d); MaxHeight = _originalMaxSize.Height * (_originalMaxSize.Height < UnlimitedSize ? scaleY : 1d); MinWidth = Math.Min(screen.WorkingArea.Width, _originalMinSize.Width * scaleX); MinHeight = Math.Min(screen.WorkingArea.Height, _originalMinSize.Height * scaleY); Logging.Debug($"Result: {MinWidth}×{MinHeight}"); if (ActualWidth > MaxWidth) { Width = MaxWidth; } else if (ActualWidth < MinWidth) { Width = MinWidth; Logging.Debug($"Clamp width to: {MinWidth}"); } if (ActualHeight > MaxHeight) { Height = MaxHeight; } else if (ActualHeight < MinHeight) { Height = MinHeight; Logging.Debug($"Clamp width to: {MinHeight}"); } }
public static WpfScreen GetScreenFrom(Window window) { WindowInteropHelper windowInteropHelper = new WindowInteropHelper(window); Screen screen = System.Windows.Forms.Screen.FromHandle(windowInteropHelper.Handle); WpfScreen wpfScreen = new WpfScreen(screen); return wpfScreen; }
private static WpfScreen GetScreenFromSide(Side side) { return (WpfScreen.GetScreenFrom(side == Side.Left ? new Point(WpfScreen.MostLeftX, 0) : new Point(WpfScreen.MostRightX, 0))); }
private void HandleMaximizeClick(object sender, RoutedEventArgs e) { var s = WpfScreen.GetScreenFrom(this); this.Top = s.WorkingArea.Top; this.Height = s.WorkingArea.Height; }
private void Init() { _screens = WpfScreen.AllScreens(); //arrange displays by X _screens.Sort((s1, s2) => (int)(s1.DeviceBounds.Left - s2.DeviceBounds.Left)); foreach (var scr in _screens) { Debug.WriteLine(scr); } _borders = new BorderBetweenDisplays[_screens.Count - 1]; var bounds = WPF_Helper.VirtualScreenBounds(); for (int i = 1; i < _screens.Count; i++) { _borders[i - 1] = new BorderBetweenDisplays() { Index = i - 1, DisplayToDisplay_X = _screens[i - 1].DeviceBounds.Right, FromDisplayToDisplay_Top = Math.Max(_screens[i].DeviceBounds.Top, _screens[i - 1].DeviceBounds.Top), FromDisplayToDisplay_Bottom = Math.Min(_screens[i].DeviceBounds.Bottom, _screens[i - 1].DeviceBounds.Bottom) }; } }
private void OnLoad(object sender, RoutedEventArgs e) { StartScreenHelpDialogHelper.ShowScreenStartHelpDialogIfFlagIsTrue(ScreenStartDialogTypes.MeshCreated); //scale left grid a little bit for monitors with resolution higher than 800*600 try { var thisWindow = Window.GetWindow(this); var wpfScreen = WpfScreen.GetScreenFrom(thisWindow); var screenWidth = wpfScreen.DeviceBounds.Width; var scaleValue = 1.0; if (screenWidth >= 1200) { scaleValue = 1.4; } else if (screenWidth >= 1000) { scaleValue = 1.2; } var scaleTransform = new ScaleTransform(scaleValue, scaleValue); LeftGrid.LayoutTransform = scaleTransform; thisWindow.WindowState = WindowState.Maximized; } catch (Exception) { } }
//try to rescale the window for a best fit private void RescaleToBest() { try { var thisWindow = Window.GetWindow(this); var wpfScreen = WpfScreen.GetScreenFrom(thisWindow); var screenWidth = wpfScreen.DeviceBounds.Width; var screenHeight = wpfScreen.DeviceBounds.Height; var desiredHorizontalScaling = GetDesiredHorizontalScaling(screenWidth); var desiredVerticalScaling = GetDesiredVerticalScaling(screenHeight); var lowerValue = desiredHorizontalScaling; if (desiredVerticalScaling < lowerValue) { lowerValue = desiredVerticalScaling; } var scaleTransform = new ScaleTransform(lowerValue, lowerValue); ParentCanvas.LayoutTransform = scaleTransform; thisWindow.WindowState = WindowState.Maximized; } catch (Exception) { } }
private void OpenWindow(WindowPositionSide side, WpfScreen screen) { if (side == WindowPositionSide.None || side == WindowPositionSide.Top) { return; } CloseWindow(); double dockwindowLeft; switch (side) { case WindowPositionSide.Left: dockwindowLeft = WpfScreen.MostLeftX; break; case WindowPositionSide.Right: dockwindowLeft = WpfScreen.MostRightX - 300; break; case WindowPositionSide.Top: return; default: throw new ArgumentOutOfRangeException(nameof(side)); } _placeholderWindow = new DockPlaceholderWindow(screen.WorkingArea.Top, dockwindowLeft, screen.WorkingArea.Height, 300); _placeholderWindow.Show(); }
private void OpenWindow(WindowPositionSide side, WpfScreen screen) { if (side == WindowPositionSide.None) { return; } CloseWindowIfExists(); double dockwindowLeft, dockwindowWidth; switch (side) { case WindowPositionSide.Left: dockwindowLeft = WpfScreen.MostLeftX; dockwindowWidth = 300; break; case WindowPositionSide.Right: dockwindowLeft = WpfScreen.MostRightX - 300; dockwindowWidth = 300; break; case WindowPositionSide.Top: return; default: throw new ArgumentOutOfRangeException("side"); } _window = new DockRangeWindow(screen.WorkingArea.Top, dockwindowLeft, screen.WorkingArea.Height, dockwindowWidth); _window.Show(); }
void HookManager_MouseMove(object sender, MouseEventArgs e) { //Side dock > top dock if (!IsEnabled) { return; } if (Mouse.LeftButton == MouseButtonState.Released) //If the user doubleclicks the window, relocates the window and releases the mouse, it doesn't get stopped { DragStop(); return; } if (MouseIsLeftRightOrTop(e.X, e.Y, out _newSide)) { var screen = WpfScreen.GetScreenFrom(new Point(e.X, e.Y)); if (NewSide == WindowPositionSide.Left || NewSide == WindowPositionSide.Right) { if (!IsAtRightOrLeftBorder) { IsAtRightOrLeftBorder = true; OpenWindow(NewSide.Value, screen); if (IsAtTop) { IsAtTop = false; } } return; } if (IsAtRightOrLeftBorder) { IsAtRightOrLeftBorder = false; CloseWindowIfExists(); } if (NewSide == WindowPositionSide.Top) { if (!IsAtTop || screen.DeviceName != DisplayingScreen) { IsAtTop = true; OpenWindow(NewSide.Value, screen); DisplayingScreen = screen.DeviceName; } } } else { OnUndocked(); if (IsAtTop) { IsAtTop = false; CloseWindowIfExists(); } if (IsAtRightOrLeftBorder) { IsAtRightOrLeftBorder = false; CloseWindowIfExists(); } } }
private void MouseHookOnMouseMove(object sender, MouseMoveEventArgs e) { if (!IsDragging || Mouse.LeftButton == MouseButtonState.Released) { return; } if (MouseIsLeftRightOrTop(e.X, e.Y, out _newSide)) { var screen = WpfScreen.GetScreenFrom(new Point(e.X, e.Y)); if (_newSide == WindowPositionSide.Left || _newSide == WindowPositionSide.Right) { if (!_isAtRightOrLeftBorder) { _isAtRightOrLeftBorder = true; OpenWindow(_newSide.Value, screen); if (_isAtTop) { _isAtTop = false; } } return; } if (_isAtRightOrLeftBorder) { _isAtRightOrLeftBorder = false; CloseWindow(); } if (_newSide == WindowPositionSide.Top) { if (!_isAtTop || screen.DeviceName != _displaingScreen) { _isAtTop = true; _displaingScreen = screen.DeviceName; } } } else { if (!_firedUndocked) { _firedUndocked = true; OnUndocked(); } if (_isAtTop) { _isAtTop = false; CloseWindow(); } if (_isAtRightOrLeftBorder) { _isAtRightOrLeftBorder = false; CloseWindow(); } } }
public void Update(SmartObservableCollection <DisplayInfo> displays) { if (Index < 0 || Index >= displays.Count) { Index = 0; } this.screen = displays[Index].screen; }
public void ApplyCurrentSide() { if (CurrentSide == DockingSide.Left || CurrentSide == DockingSide.Right) { _basewindow.Left = CurrentSide == DockingSide.Left ? WpfScreen.MostLeftX : WpfScreen.MostRightX - 300; var screen = WpfScreen.GetScreenFrom(new Point(_basewindow.Left, 0)); _basewindow.Top = screen.WorkingArea.Top; WindowHeight = screen.WorkingArea.Height; } }
private void ValidateHeight() { var s = WpfScreen.GetScreenFrom(this); if (this.Height > s.WorkingArea.Height) { this.Top = s.WorkingArea.Top; this.Height = s.WorkingArea.Height; } }
public static WpfScreen GetScreenFrom(Point point) { int x = (int)Math.Round(point.X); int y = (int)Math.Round(point.Y); // are x,y device-independent-pixels ?? System.Drawing.Point drawingPoint = new System.Drawing.Point(x, y); Screen screen = System.Windows.Forms.Screen.FromPoint(drawingPoint); WpfScreen wpfScreen = new WpfScreen(screen); return wpfScreen; }
private VerticalOrientation GetVerticalOrientation() { WpfScreen screen = WpfScreen.GetScreenFrom(this); if (Top > (screen.DeviceBounds.Height / 2)) { return(VerticalOrientation.Bottom); } return(VerticalOrientation.Top); }
private void MagicTriggerOnMouseMove(object sender, MouseEventArgs e) { Trace.WriteLine("MagicTrigger: mouse move"); if (!IsMagicArrowVisible && !_isInZone && PositionIsOk(_movedOutSide, Cursor.Position.X, WpfScreen.MostLeftX - 2, WpfScreen.MostRightX)) { _isInZone = true; var p = e.GetPosition(_magicTrigger); var screen = WpfScreen.GetScreenFrom(p); ShowMagicArrow(p.Y + screen.WorkingArea.Top, _movedOutSide); } }
public static List <DisplayInfo> GetDisplays() { List <DisplayInfo> list = new List <DisplayInfo>(); List <WpfScreen> screens = WpfScreen.AllScreens(); for (int i = 0; i < screens.Count; i++) { list.Add(new DisplayInfo(screens[i], i)); } return(list); }
/// <summary> /// Se lo SS è visibile, mi indica in quale schermo è posizionato /// </summary> /// <returns>-1 se non è visibile, altrimenti il numero dello schermo</returns> public WpfScreen getScreenSlideShow() { if (isSlideShowVisible) { return(WpfScreen.GetScreenFrom(_slideShowWindow)); } else { return(null); } }
private HorizontalOrientation GetHorizontalOrientation() { WpfScreen screen = WpfScreen.GetScreenFrom(this); if (Left > (screen.DeviceBounds.Width / 2)) { return(HorizontalOrientation.Right); } return(HorizontalOrientation.Left); }
private void Window_Loaded(object sender, RoutedEventArgs e) { Sentry.AddHandler(this.Dispatcher); WpfScreen screen = WpfScreen.FromWindow(this); if (!screen.WorkingArea.IntersectsWith(new Rect(this.Left, this.Top, this.Width, this.Height))) { this.Left = screen.WorkingArea.Left + 200; this.Top = screen.WorkingArea.Top + 200; } }
/// <summary> /// Uso lo schermo indicato nella geometria stessa /// </summary> /// <param name="geom"></param> /// <returns></returns> public static bool verificaProiettabile(GeometriaFinestra geom) { // Verifico se lo schermo indicato esiste ancora. Potrebbe essere stato scollegato if (geom.deviceEnum >= 0 && geom.deviceEnum < Screen.AllScreens.Count()) { return(verificaProiettabile(WpfScreen.GetScreenFrom(geom.deviceEnum), geom)); } else { return(false); } }
public void RefreshHostWindow(bool saveInformation) { if (MagicArrow.DockManager.CurrentSide == DockingSide.None) { ApplyHostWindow(AdvancedWindowSkin, saveInformation); } else { ApplyHostWindow(SmartWindowSkin, saveInformation); Height = WpfScreen.GetScreenFrom(new Point(Left, 0)).WorkingArea.Height; } }
void strokewindow_MouseMove(object sender, MouseEventArgs e) { Hurricane.Views.Test.TestWindow.AddMessage("Stroke: Mouse Move"); if (!MagicArrowIsShown && !IsInZone && StrokeWindow.PositionIsOk(_movedoutside, Cursor.Position.X, WpfScreen.MostLeftX - 2, WpfScreen.MostRightX)) { IsInZone = true; Point p = e.GetPosition(Strokewindow); var screen = WpfScreen.GetScreenFrom(p); ShowMagicArrow(p.Y + screen.WorkingArea.Top, _movedoutside); } MouseWasOver = true; }
private void StartupConfigWindow(AppSettings settings) { if (settings.StartupLocation == ExtendedWindowStartupLocation.CenterScreen) { WindowStartupLocation = WindowStartupLocation.CenterScreen; WindowState = ConvertWindowStateEnum(settings.StartupState); Left = settings.StartupPositionX; Top = settings.StartupPositionY; Width = settings.StartupPositionWidth; Height = settings.StartupPositionHeight; } else if (settings.StartupLocation == ExtendedWindowStartupLocation.Manual) { WindowStartupLocation = WindowStartupLocation.Manual; WindowState = ConvertWindowStateEnum(settings.StartupState); Left = settings.StartupPositionX; Top = settings.StartupPositionY; Width = settings.StartupPositionWidth; Height = settings.StartupPositionHeight; } else if (settings.StartupLocation == ExtendedWindowStartupLocation.ScreenBottomLeft) { var screen = WpfScreen.GetScreenFrom(this); WindowStartupLocation = WindowStartupLocation.Manual; WindowState = ConvertWindowStateEnum(settings.StartupState); Left = screen.WorkingArea.Left + 5; Top = screen.WorkingArea.Bottom - settings.StartupPositionHeight - 5; Width = settings.StartupPositionWidth; Height = settings.StartupPositionHeight; } else if (settings.StartupLocation == ExtendedWindowStartupLocation.ScreenLeft) { var screen = WpfScreen.GetScreenFrom(this); WindowStartupLocation = WindowStartupLocation.Manual; WindowState = ConvertWindowStateEnum(settings.StartupState); Left = screen.WorkingArea.Left + 5; Top = screen.WorkingArea.Top + 5; Width = settings.StartupPositionWidth; Height = screen.WorkingArea.Height - 10; } }
private IList <ShellWindow> CreateShellWindows() { var shellWindows = new List <ShellWindow>(); var primary = WpfScreen.Primary; var shellWindow1 = new ShellWindow(); shellWindow1.WindowId = ShellConst.WindowId_Shell1; shellWindow1.Left = primary.DeviceBounds.Left; shellWindow1.Top = primary.DeviceBounds.Top; shellWindow1.Width = primary.DeviceBounds.Width; shellWindow1.Height = primary.DeviceBounds.Height; shellWindow1.Title = primary.DeviceName; shellWindow1.Background = Brushes.YellowGreen; shellWindows.Add(shellWindow1); ShellWindow shellWindow2 = null; var second = WpfScreen.AllScreens().FirstOrDefault(x => !x.IsPrimary); if (second != null) { shellWindow2 = new ShellWindow(); shellWindow2.WindowId = ShellConst.WindowId_Shell2; shellWindow2.Left = second.DeviceBounds.Left; shellWindow2.Top = second.DeviceBounds.Top; shellWindow2.Width = second.DeviceBounds.Width; shellWindow2.Height = second.DeviceBounds.Height; shellWindow2.Title = second.DeviceName; shellWindow2.Background = Brushes.DarkGray; shellWindows.Add(shellWindow2); } var shellApi1 = new ShellApi(this, shellWindow1, shellWindows.ToArray()); shellWindow1.BindShellApi(shellApi1); ShellApiContext.Current.ShellApi1 = shellApi1; if (shellWindow2 != null) { var shellApi2 = new ShellApi(this, shellWindow2, shellWindows.ToArray()); shellWindow2.BindShellApi(shellApi2); ShellApiContext.Current.ShellApi2 = shellApi2; } return(shellWindows); }
public static GeometriaFinestra creaGeometriaDaScreen(WpfScreen wpfScreen) { // Creo una geometria dalle dimensioni del monitor. return(new GeometriaFinestra() { Left = (int)wpfScreen.WorkingArea.Left, Top = (int)wpfScreen.WorkingArea.Top, Width = (int)wpfScreen.WorkingArea.Width, Height = (int)wpfScreen.WorkingArea.Height, fullScreen = false, // ?? questo effettivamente non è un valore dello schermo ma della finestra deviceEnum = wpfScreen.deviceEnum }); }
protected override void OnLocationChanged(EventArgs e) { // Co-ordinates go from top-left, top-right, bottom-left, bottom-right // Check for snapping between the edges of windows var screen = WpfScreen.GetScreenFrom(new Point(Left, Top)); CheckWindowCoordinates(screen.WorkingArea); // Check for snapping between other widgets on the screen foreach (var widget in Application.Current.Windows.Cast <Window>().Where(w => w is WidgetBase)) { CheckWidgetCoordinates((WidgetBase)widget); } }