Skip to content

Dismiss the tray menu when clicking away from it - #3

Merged
dvdstelt merged 1 commit into
mainfrom
fix/tray-menu-dismiss
Jul 15, 2026
Merged

Dismiss the tray menu when clicking away from it#3
dvdstelt merged 1 commit into
mainfrom
fix/tray-menu-dismiss

Conversation

@dvdstelt

Copy link
Copy Markdown
Owner

Summary

A hand-shown tray ContextMenuStrip never receives foreground activation, so clicking outside the menu did not close it — you were stuck opening an item to dismiss it. Calling SetForegroundWindow on the menu right before Show(...) (the classic Win32 tray-menu fix) restores normal click-away dismissal.

Changes

  • NativeMethods.cs — declare SetForegroundWindow.
  • TrayIcon.cs — bring the process to the foreground before showing the menu.

Testing

  • dotnet build clean.
  • Verified by hand: right-click to open, click elsewhere → menu closes immediately; upward placement and items still work.

A hand-shown tray ContextMenuStrip never gets foreground activation, so
clicking outside it did not close it: you were stuck opening an item to
dismiss the menu. Call SetForegroundWindow on the menu before showing it
(the classic Win32 tray fix) so click-away closes it normally.
@dvdstelt dvdstelt self-assigned this Jul 15, 2026
@dvdstelt
dvdstelt merged commit 614d74f into main Jul 15, 2026
1 check passed
@dvdstelt
dvdstelt deleted the fix/tray-menu-dismiss branch July 15, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant