private void SetDockType(DockType Dock) { switch (Dock) { case DockType.None: { toolStripDockNone.Checked = true; toolStripDockLeft.Checked = false; toolStripDockTop.Checked = false; toolStripDockRight.Checked = false; toolStripDockBottom.Checked = false; } break; case DockType.Left: { toolStripDockNone.Checked = false; toolStripDockLeft.Checked = true; toolStripDockTop.Checked = false; toolStripDockRight.Checked = false; toolStripDockBottom.Checked = false; } break; case DockType.Top: { toolStripDockNone.Checked = false; toolStripDockLeft.Checked = false; toolStripDockTop.Checked = true; toolStripDockRight.Checked = false; toolStripDockBottom.Checked = false; } break; case DockType.Right: { toolStripDockNone.Checked = false; toolStripDockLeft.Checked = false; toolStripDockTop.Checked = false; toolStripDockRight.Checked = true; toolStripDockBottom.Checked = false; } break; case DockType.Bottom: { toolStripDockNone.Checked = false; toolStripDockLeft.Checked = false; toolStripDockTop.Checked = false; toolStripDockRight.Checked = false; toolStripDockBottom.Checked = true; } break; } this.dock = Dock; lastPosition = Win32Interop.Rect.Zero(); }
private void StartUpdateTimer() { lastPosition = Win32Interop.Rect.Zero(); mainWindowHandle = Win32Window.GetCurrentProcessMainWindowHandle(); if (mainWindowHandle != IntPtr.Zero) { windowUpdateTimer = new System.Threading.Timer(new TimerCallback(ViewerPosUpdateHandler), null, Timeout.Infinite, 300); } else { toolStripDock.Enabled = false; } }
private void ViewerPosUpdate(Win32Interop.Rect WindowPosition) { switch (dock) { case DockType.None: break; case DockType.Left: { Screen screen = Screen.FromPoint(new Point(WindowPosition.Left, WindowPosition.Top)); this.Left = screen.WorkingArea.Left; this.Top = WindowPosition.Top; this.Height = WindowPosition.Bottom - WindowPosition.Top; this.Width = (WindowPosition.Left - screen.WorkingArea.Left); } break; case DockType.Top: { this.Left = WindowPosition.Left; this.Top = WindowPosition.Top - this.Height; this.Width = WindowPosition.Right - WindowPosition.Left; } break; case DockType.Right: { this.Left = WindowPosition.Right; this.Top = WindowPosition.Top; this.Height = WindowPosition.Bottom - WindowPosition.Top; Screen screen = Screen.FromPoint(new Point(WindowPosition.Left, WindowPosition.Top)); this.Width = screen.WorkingArea.Width - (WindowPosition.Right - screen.WorkingArea.Left); } break; case DockType.Bottom: { this.Left = WindowPosition.Left; this.Top = WindowPosition.Bottom; this.Width = WindowPosition.Right - WindowPosition.Left; } break; } }
private void ViewerPosUpdateHandler(object obj) { if (mainWindowHandle != IntPtr.Zero && dock != DockType.None) { if (Win32Interop.IsWindowVisible(mainWindowHandle)) { if (!Win32Interop.IsZoomed(mainWindowHandle)) { Win32Interop.Rect currentPosition; Win32Interop.GetWindowRect(mainWindowHandle, out currentPosition); if (!currentPosition.IsSame(lastPosition)) { this.SafeInvoke(() => { ViewerPosUpdate(currentPosition); }); lastPosition = currentPosition; } } } } }