winforms-system-tray

Implements WinForms main forms that minimize or close into the Windows notification area.

1|1|Updated Jun 12, 2022
One-click install
npx skills add https://github.com/KlausLoeffelmann/WinFormsDevTools --skill winforms-system-tray-klausloeffelmann
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: winforms-system-tray
Source: https://github.com/KlausLoeffelmann/WinFormsDevTools/tree/main/.github/skills/winforms-system-tray
Command: npx skills add https://github.com/KlausLoeffelmann/WinFormsDevTools --skill winforms-system-tray-klausloeffelmann

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? WinForms applications that should keep running in the Windows notification area (SysTray) often suffer from taskbar flicker, lost window bounds, and inconsistent close/quit behavior when developers wire up NotifyIcon incorrectly. This Skill provides a proven implementation pattern for close-to-tray and minimize-to-tray main forms. ## Core Features & Use Cases - Tray Behavior Planning: Guides the choice between close-to-tray, minimize-to-tray, or both, and adjusts menu integration accordingly. - Correct Hide/Restore Ordering: Handles the ShowInTaskbar handle-recreation pitfall by hiding the form before changing taskbar participation, avoiding flicker and focus issues. - NotifyIcon and Persistence Patterns: Provides context menu, double-click restore, shared Quit command, and bounds/state persistence so the form never restores to minimized tray coordinates. - Use Case: A background utility app should disappear to the tray when the user clicks the close button, restore on tray double-click, and only exit via a File / Quit menu item wired to the same Quit method. ## Quick Start Use the winforms-system-tray skill to make my main form close to the system tray with a restore and quit context menu.

Frequently Asked Questions about winforms-system-tray

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I minimize a WinForms app to the system tray?▼

Override OnResize and check for FormWindowState.Minimized, then call a MinimizeToTray method that saves bounds, hides the form, shows the NotifyIcon, and sets ShowInTaskbar to false. Restore by reversing the order: ShowInTaskbar true, Show, then set WindowState to Normal.

How to make the WinForms close button hide to tray instead of exiting?▼

Override OnFormClosing, cancel only closes where CloseReason is UserClosing, and route them to your tray-hide method. Keep a private allow-close flag that a dedicated Quit method sets before calling Close so the app can still exit for real.

Why does my WinForms form flicker or lose focus when hiding to the tray?▼

Changing ShowInTaskbar can recreate the form handle, causing taskbar pinning, focus, and flicker problems. Hide the form first, then change ShowInTaskbar while it is already hidden, and restore in the opposite order.

How do I add a context menu to a NotifyIcon in WinForms?▼

Assign a ContextMenuStrip to the NotifyIcon with Restore, optional Options, and Quit items. Handle double-click to restore the form and left-click to show the menu at Cursor.Position, wiring Quit to the same method as any File / Quit menu item.

Why does my form restore to the wrong position after being in the tray?▼

The app saved minimized tray bounds as the normal form size. Capture Bounds when WindowState is Normal, or RestoreBounds otherwise, before hiding to the tray, and persist whether the app was tray-hidden so startup can restore correctly.