private void MouseHook_MouseMove(object sender, MouseEventArgs e) { if (m_mouseLeftDown && !OwnApplicationActive()) { // Of course we have to be visible! if (Visible) { // Don't get the form on top until we're close to it if (Math.Sqrt(Math.Pow(Location.X + Size.Width / 2 - Cursor.Position.X, 2) + Math.Pow(Location.Y + Size.Height / 2 - Cursor.Position.Y, 2)) <= 48) { TopMost = true; } else { TopMost = false; } } // Autohide stuff if (TaskBar.GetTaskBarState() == TaskBar.TaskBarState.AutoHide) { if (!MouseInTaskbar()) { m_mouseWasInTaskbar = false; } else { if (!m_mouseWasInTaskbar) { m_mouseWasInTaskbar = true; m_taskbarAutoHideTimer.Interval = 750; m_taskbarAutoHideTimer.Tick += (sender2, e2) => { ShowDrop(); m_taskbarAutoHideTimer.Stop(); }; } } } } }
private static bool MouseInTaskbar() { return(TaskBar.GetTaskBarRectangle().Contains(Cursor.Position)); }
public void ShowDrop() { // Somehow this can be run even when disposed... if (IsDisposed) { return; } // Don't do anything if we're out of the taskbar with auto-hide if (TaskBar.GetTaskBarState() == TaskBar.TaskBarState.AutoHide && !MouseInTaskbar()) { return; } // Now then... m_lastNotifyIconPoint = m_owner.GetLocation(); Point _notifyIconLocation = m_lastNotifyIconPoint; Hide(); // Stuff Size _taskbarSize = TaskBar.GetTaskBarSize(); Point _taskbarLocation = TaskBar.GetTaskBarLocation(); // If we get (-1, -1), or a screwed up position, then don't bother with if (_notifyIconLocation != new Point(-1, -1)) { // We've got a find, yessiree! m_firstFind = true; // Anyway, the task at hand; where does our drop zone go? switch (TaskBar.GetTaskBarEdge()) { case TaskBar.TaskBarEdge.Bottom: Top = _taskbarLocation.Y + 2; Left = _notifyIconLocation.X; Width = 24; Height = _taskbarSize.Height; break; case TaskBar.TaskBarEdge.Top: Top = -2; Left = _notifyIconLocation.X; Width = 24; Height = _taskbarSize.Height; break; case TaskBar.TaskBarEdge.Left: Top = _notifyIconLocation.Y; Left = -2; Width = _taskbarSize.Width; Height = 24; break; case TaskBar.TaskBarEdge.Right: Top = _notifyIconLocation.Y; Left = _taskbarLocation.X + 2; Width = _taskbarSize.Width; Height = 24; break; } } // We still want to show again even if we get (-1, -1), but only if we've found it at least once! if (m_firstFind) { // Post-disposal exception horror fix pt.2 try { Show(); TopMost = false; } catch { } } }