public static GetScreenFrom ( Point, point ) : WpfScreen, | ||
point | Point, | |
return | WpfScreen, |
void Update() { var screen = WpfScreen.GetScreenFrom(this); var offsets = new[] { new { Pos = Position.Left, Value = Math.Abs(screen.WorkingArea.Left - Left) }, new { Pos = Position.Top, Value = Math.Abs(screen.WorkingArea.Top - Top) }, new { Pos = Position.Right, Value = Math.Abs(screen.WorkingArea.Right - Left) }, new { Pos = Position.Bottom, Value = Math.Abs(screen.WorkingArea.Bottom - Top) } }; var primary = offsets.OrderBy(x => x.Value).FirstOrDefault().Pos; currentPosition = primary; switch (primary) { case Position.Left: Left = screen.WorkingArea.Left; rootPanel.Orientation = Orientation.Vertical; break; case Position.Top: Top = screen.WorkingArea.Top; rootPanel.Orientation = Orientation.Horizontal; break; case Position.Right: Left = screen.WorkingArea.Right - 32; rootPanel.Orientation = Orientation.Vertical; break; case Position.Bottom: Top = screen.WorkingArea.Bottom - 32; rootPanel.Orientation = Orientation.Horizontal; break; } RegistrySettings.Top = (int)Top; RegistrySettings.Left = (int)Left; RegistrySettings.Orientation = rootPanel.Orientation; }
private void OnLoad(object sender, RoutedEventArgs e) { StartScreenHelpDialogHelper.ShowScreenStartHelpDialogIfFlagIsTrue(ScreenStartDialogTypes.CreateReady); //scale grid a little bit for monitors with resolution less than 600 height try { var thisWindow = Window.GetWindow(this); var wpfScreen = WpfScreen.GetScreenFrom(thisWindow); var screenHeight = wpfScreen.DeviceBounds.Height; if (screenHeight <= 600) { const double scaleValue = .8; var scaleTransform = new ScaleTransform(scaleValue, scaleValue); ParentGrid.LayoutTransform = scaleTransform; } thisWindow.WindowState = WindowState.Maximized; } catch (Exception) { } }
private void UpdateContentWindow() { if (_dlg != null) { var s = WpfScreen.GetScreenFrom(this); if (this.Top < _dlg.Height) // no space above, place bellow { var height = this.Top + this.ActualHeight; if (height + _dlg.Height < s.WorkingArea.Height) { _dlg.Top = height; } else // Not fit bellow { _dlg.Top = this.Top; _dlg.Left = this.Left - _dlg.Width; if (_dlg.Left < 0) { _dlg.Left = this.Left + this.ActualWidth; } return; } } else { _dlg.Top = this.Top - _dlg.Height; } _dlg.Left = (this.Left + this.ActualWidth) - _dlg.Width; } }
private void SnapWindowToEdge() { var s = WpfScreen.GetScreenFrom(this); var treshold = 30; // End Right var right = this.Left + this.Width; if ((right > s.DeviceBounds.Right - treshold && right < s.DeviceBounds.Right + treshold)) { this.Left = s.DeviceBounds.Width - this.Width; } // End Left var left = this.Left; if ((left > s.DeviceBounds.Left - treshold && left < s.DeviceBounds.Left + treshold)) { this.Left = s.DeviceBounds.Left; } var bottom = this.Top + this.Height; if ((bottom > s.WorkingArea.Bottom - treshold && bottom < s.WorkingArea.Bottom + treshold)) { this.Top = s.WorkingArea.Height - this.Height; } var top = this.Top; if ((top > s.WorkingArea.Top - treshold && top < s.WorkingArea.Top + treshold)) { this.Top = s.WorkingArea.Top; } }
private Vector CoerceWindowBound(Vector newPoint) { // Snap to the current desktop border var screen = WpfScreen.GetScreenFrom(_window); var wa = screen.WorkingArea; if (newPoint.X < wa.Top) { newPoint.X = wa.Top; } if (newPoint.Y < wa.Left) { newPoint.Y = wa.Left; } if (_window.Width + newPoint.X > wa.Right) { newPoint.X = wa.Right - _window.Width; } if (_window.Height + newPoint.Y > wa.Bottom) { newPoint.Y = wa.Bottom - _window.Height; } return(newPoint); }
public void CenterWindowOnScreen() { var screen = WpfScreen.GetScreenFrom(this).WorkingArea; Left = (screen.Width / 2) - (Width / 2); Top = (screen.Height / 2) - (Height / 2); }
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 { if (!_firedUndocked) { _firedUndocked = true; OnUndocked(); } if (IsAtTop) { IsAtTop = false; CloseWindowIfExists(); } if (IsAtRightOrLeftBorder) { IsAtRightOrLeftBorder = false; CloseWindowIfExists(); } } }
/// <summary> /// Aggiorno solo in memoria (non persisto sulla configurazione) /// </summary> internal void memorizzaGeometriaFinestraSlideShow() { WpfScreen scrn = WpfScreen.GetScreenFrom(_slideShowWindow); this.geomSS = creaGeometriaDaWindow(_slideShowWindow); }
/// <summary> /// Se la finestra dello slide show non è aperta (o non è istanziata) /// la creo sul momento /// </summary> private bool forseApriSnapshotPubblicoWindow() { // Se è già aperta, non faccio niente if (_snapshotPubblicoWindow != null) { return(false); } IInputElement elementoKeyboardInfuocato = Keyboard.FocusedElement; // Apro la finestra modeless // Create a window and make this window its owner _snapshotPubblicoWindow = new SnapshotPubblicoWindow(); _snapshotPubblicoWindow.Closed += chiusoSnapshotPubblicoWindow; if (_slideShowWindow != null) { // Se ho lo ss attivo, allora devo prendere il suo posto if (_slideShowWindow.WindowState == WindowState.Maximized) { // In questo caso non posso massimizzare a mia volta :-( // Se sono sul secondo monitor, devo lavorare come se fosse in normal WpfScreen scrn = WpfScreen.GetScreenFrom(_slideShowWindow); _snapshotPubblicoWindow.Height = scrn.WorkingArea.Height; _snapshotPubblicoWindow.Width = scrn.WorkingArea.Width; _snapshotPubblicoWindow.Top = scrn.WorkingArea.Top; _snapshotPubblicoWindow.Left = scrn.WorkingArea.Left; } else { _snapshotPubblicoWindow.Height = _slideShowWindow.Height; _snapshotPubblicoWindow.Width = _slideShowWindow.Width; _snapshotPubblicoWindow.Top = _slideShowWindow.Top; _snapshotPubblicoWindow.Left = _slideShowWindow.Left; } _snapshotPubblicoWindow.WindowState = WindowState.Normal; } else { // valorizzo la geometria del form = a quella del form slide show (praticamente lo ricopro) _snapshotPubblicoWindow.Height = Configurazione.UserConfigLumen.geometriaFinestraSlideShow.Height; _snapshotPubblicoWindow.Width = Configurazione.UserConfigLumen.geometriaFinestraSlideShow.Width; _snapshotPubblicoWindow.Top = Configurazione.UserConfigLumen.geometriaFinestraSlideShow.Top; _snapshotPubblicoWindow.Left = Configurazione.UserConfigLumen.geometriaFinestraSlideShow.Left; /* * if( Configurazione.UserConfigLumen.fullScreen ) * _snapshotPubblicoWindow.WindowState = WindowState.Maximized; * else * _snapshotPubblicoWindow.WindowState = WindowState.Normal; * */ } _snapshotPubblicoWindow.Show(); _snapshotPubblicoWindow.Topmost = true; // Riposiziono il fuoco sul componente che lo deteneva prima di aprire la finestra Keyboard.Focus(elementoKeyboardInfuocato); if (Configurazione.UserConfigLumen.geometriaFinestraSlideShow.fullScreen) { _snapshotPubblicoWindow.WindowState = WindowState.Maximized; } else { _snapshotPubblicoWindow.WindowState = WindowState.Normal; } return(true); }
/// <summary> /// Controllo che la geometria della finestra sia posizionabile in un monitor. /// </summary> private void gestisciPosizione() { // Per prima cosa, provo a posizionare la finestra nella posizione indicata in configurazione // Mi copio in locale la geometria della finestra per poterla modificare con lo spostamento geoCurrent = (GeometriaFinestra)Configurazione.UserConfigLumen.geometriaFinestraSlideShow.Clone(); WpfScreen scrn = WpfScreen.GetScreenFrom(geoCurrent.deviceEnum); if (scrn == null) { scrn = WpfScreen.GetFirstScreen(); // Prendo quello di default } // this.WindowStartupLocation = WindowStartupLocation.Manual; _giornale.Debug("SlideShow Primary Device Info:\n " + WpfScreen.Primary.ToDebugString()); _giornale.Debug("SlideShow Configuration Device Info:\n " + scrn.ToDebugString()); if (geoCurrent.deviceEnum != scrn.deviceEnum) { _giornale.Debug("Il monitor impostato non è stato trovato!!!"); geoCurrent.deviceEnum = WpfScreen.Primary.deviceEnum; } if (!verificaProiettabile(scrn, geoCurrent)) { _giornale.Debug("I valori calcolati non sono ammissibili utilizzo quelli di default"); this.geoCurrent = Configurazione.creaGeometriaSlideShowDefault(); } //Se ho messo il full screen resetto i Top e Left if (geoCurrent.fullScreen) { Screen s = (Screen)Screen.AllScreens.GetValue(geoCurrent.deviceEnum); System.Drawing.Rectangle r = s.WorkingArea; geoCurrent.Top = r.Top; geoCurrent.Left = r.Left; } else if (geoCurrent.screenHeight != (int)scrn.WorkingArea.Height || geoCurrent.screenWidth != (int)scrn.WorkingArea.Width) { _giornale.Debug("Ricalcolo la geometria dello slideShow in base al nuovo monitor"); _giornale.Debug("*** VALORI VECCHI ***"); _giornale.Debug(geoCurrent.ToDebugString()); geoCurrent.Top = geoCurrent.Top <= 0 ? 0 : (int)(geoCurrent.Top * scrn.WorkingArea.Height / geoCurrent.screenHeight); geoCurrent.Left = geoCurrent.Left <= 0 ? 0 : (int)(geoCurrent.Left * scrn.WorkingArea.Width / geoCurrent.screenWidth); geoCurrent.Height = (int)(geoCurrent.Height * scrn.WorkingArea.Height / geoCurrent.screenHeight); geoCurrent.Width = (int)(geoCurrent.Width * scrn.WorkingArea.Width / geoCurrent.screenWidth); Screen s = (Screen)Screen.AllScreens.GetValue(geoCurrent.deviceEnum); System.Drawing.Rectangle r = s.WorkingArea; geoCurrent.screenHeight = (int)scrn.WorkingArea.Height; geoCurrent.screenWidth = (int)scrn.WorkingArea.Width; _giornale.Debug("*** VALORI RICALCOLATI ***"); _giornale.Debug(geoCurrent.ToDebugString()); } GestoreFinestrePubbliche.risposizionaFinestra(this, geoCurrent); // Il salvataggio della posizione, lo farei solo su richiesta esplicita dell'utente if (salvaNuoviValori) { _giornale.Debug("Devo salvare i nuovi valori ricalcolati"); _giornale.Debug("Devo salvare la configurazione utente su file xml"); UserConfigSerializer.serializeToFile(cfg); _giornale.Info("Salvata la configurazione utente su file xml"); } }