private void Window_LocationChanged(object sender, EventArgs e) { if (!_isRepositioning) { // Position was changed by Windows, e.g. due to screen resizing or app reloading // Snap to screen boundaries _isRepositioning = true; var scale = LayoutUtilities.GetDpiScale(this); scale = DpiUtilities.GetSystemScale(); scale = SystemScale; var screen = System.Windows.Forms.Screen.FromPoint(new System.Drawing.Point((int)Left, (int)Top)); Left = Math.Min(Math.Max(Left, screen.WorkingArea.Left / scale.X), screen.WorkingArea.Right / scale.X - ActualWidth); Top = Math.Min(Math.Max(Top, screen.WorkingArea.Top / scale.Y), screen.WorkingArea.Bottom / scale.Y - ActualHeight); // Make sure docking state is correct var dockState = ToolsDockState(scale, screen); Trace.WriteLine("Window position changed, new position: (" + Left + ", " + Top + "), Current dock state:" + _currentDockState + ", Dock state for position:" + dockState); if (dockState != _currentDockState) { // Adjust tool window position to match the old dock state switch (_currentDockState) { case DockState.Top: Top = screen.WorkingArea.Top / scale.Y; break; case DockState.Left: Left = screen.WorkingArea.Left / scale.X; break; case DockState.Right: Left = screen.WorkingArea.Right / scale.X - ActualWidth; break; case DockState.Bottom: Top = screen.WorkingArea.Bottom / scale.Y - ActualHeight; break; case DockState.Middle: Left = (screen.WorkingArea.Left + screen.WorkingArea.Right) / 2 / scale.X - ActualWidth / 2; Top = (screen.WorkingArea.Top + screen.WorkingArea.Bottom) / 2 / scale.Y - ActualHeight / 2; break; } Trace.WriteLine("Adjusted dockState:" + _currentDockState + ", adjusted position: (" + Left + ", " + Top + ")"); } _isRepositioning = false; Settings.Default.ToolDocking = _currentDockState.ToString(); Settings.Default.ToolPosition = new System.Drawing.Point((int)Left, (int)Top); Settings.Default.Save(); } }
/// <summary> /// Shows the panel /// </summary> private void AutoShowPanel(Object sender, System.EventArgs e) { this.autoShow.Stop(); if (this.textLog.TextLength > 0) { DockContent panel = this.Parent as DockContent; DockState ds = panel.VisibleState; if (!panel.Visible || ds.ToString().EndsWith("AutoHide")) { panel.Show(); if (ds.ToString().EndsWith("AutoHide")) { panel.Activate(); } } } }
/// <summary> /// Shows the panel /// </summary> private void AutoShowPanel(Object sender, System.EventArgs e) { this.autoShow.Stop(); if (this.entriesView.Items.Count > 0) { DockContent panel = this.Parent as DockContent; DockState ds = panel.VisibleState; if (!panel.Visible || ds.ToString().EndsWithOrdinal("AutoHide")) { panel.Show(); if (ds.ToString().EndsWithOrdinal("AutoHide")) { panel.Activate(); } } } }
private void RunToolForm_FormClosed(object sender, FormClosedEventArgs e) { AddInDockState dockState = (AddInDockState)Enum.Parse(typeof(AddInDockState), DockState.ToString()); HostServicesSingleton.HostServices.PersistedDockStateService.AddState(this.GetType(), dockState); _instance = null; }