private void MouseHook_MouseMove(object sender, MouseEventArgs e) { if (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) { bool mouseInTaskbar = MouseInTaskbar(); if (mouseDownAndWasInTaskbar != mouseInTaskbar) { mouseDownAndWasInTaskbar = mouseInTaskbar; ShowDrop(); } } } else { mouseDownAndWasInTaskbar = false; } }
public void ShowDrop() { // Wrong thread? if (InvokeRequired) { Invoke(new MethodInvoker(() => ShowDrop())); return; } // 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()) { Hide(); return; } // Now then... lastNotifyIconPoint = _owner.GetLocation(false); Hide(); // Point? _owner.DropRefreshCallback(lastNotifyIconPoint.HasValue); // Don't bother doing anything if we don't have a value if (lastNotifyIconPoint.HasValue) { Point notifyIconLocation = lastNotifyIconPoint.Value; // Stuff Size taskbarSize = Taskbar.GetTaskbarSize(); Point taskbarLocation = Taskbar.GetTaskbarLocation(); // We've got a find, yessiree! 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 fail to find, but only if we've found it at least once! if (firstFind) { // Post-disposal exception horror fix pt.2 try { Show(); TopMost = false; } catch { } } } }