public static extern bool GetMonitorInfo( IntPtr hMonitor, ref MonitorInfo lpmi );
private void UpdateCurrentMonitor( Rect windowRect ) { if( _currentMonitor == null || !_currentMonitor.MonitorArea.IntersectsWith( windowRect ) ) { _currentMonitor = _desktopInfo.FindMonitor( windowRect ); } }
private void OnDesktopChanged( object sender, EventArgs e ) { if( !IsDockStateValidForMonitor( _currentState, _currentMonitor ) ) { _currentMonitor = null; } if( _currentMonitor != null ) { Rect windowRect = GetParentWindowRect(); windowRect.Location = CalculateParentDockedPosition( _currentState, windowRect.Location ); EnsureWindowRectIsInMonitor( ref windowRect, _currentMonitor ); _parent.Left = windowRect.X; _parent.Top = windowRect.Y; } else { UpdateState( DockState.Floating ); MoveParentToPrimaryMonitor(); } }
private bool IsDockStateValidForMonitor( DockState state, MonitorInfo monitor ) { if( monitor == null ) return false; if( monitor.IsStale ) return false; switch( _currentState ) { case DockState.LeftDock: if( _currentMonitor.HasLeftTaskbar ) return false; break; case DockState.TopDock: if( _currentMonitor.HasTopTaskbar ) return false; break; case DockState.RightDock: if( _currentMonitor.HasRightTaskbar ) return false; break; case DockState.BottomDock: if( _currentMonitor.HasBottomTaskbar ) return false; break; default: break; } return true; }
private void EnsureWindowRectIsInMonitor( ref Rect windowRect, MonitorInfo monitor ) { if( windowRect.Left < monitor.MonitorArea.Left ) { windowRect.X = monitor.MonitorArea.Left; } else if( windowRect.Right > monitor.MonitorArea.Right ) { windowRect.X = monitor.MonitorArea.Right - windowRect.Width; } if( windowRect.Top < monitor.MonitorArea.Top ) { windowRect.Y = monitor.MonitorArea.Top; } else if( windowRect.Bottom > monitor.MonitorArea.Bottom ) { windowRect.Y = monitor.MonitorArea.Bottom - windowRect.Height; } }
public static extern bool GetMonitorInfo(IntPtr hMonitor, ref MonitorInfo lpmi);