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; } }
/// <summary> /// Determines whether the specified System.Drawing.Rectangle is contained within the Windows 7 notification area fly-out. /// Note that this function will return false if the fly-out is closed, or if run on older versions of Windows. /// </summary> /// <param name="point">System.Drawing.Rectangle to test.</param> /// <returns>True if the notify icon is in the fly-out, false if not.</returns> public static bool IsRectangleInFlyOut(Rectangle rectangle) { if (!SysInfo.IsWindows7OrLater) { return(false); } Rectangle taskbarRect = Taskbar.GetTaskbarRectangle(); // Don't use Rectangle.IntersectsWith since we want to check if it's ENTIRELY inside return(rectangle.Left > taskbarRect.Right || rectangle.Right < taskbarRect.Left || rectangle.Bottom < taskbarRect.Top || rectangle.Top > taskbarRect.Bottom); }
private static bool MouseInTaskbar() { return(Taskbar.GetTaskbarRectangle().Contains(Cursor.Position)); }
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 { } } } }