0

I'm writing a System Tray based app with C# and I wonder if there's a pre-existing class I can reuse. Basically, the behavior is very similar to the standard Windows volume control and calendar widgets:

  • When the notify icon is clicked, a form/dialog is popped up. If the "show hidden icons" button was clicked to access the notify icon, it'll be closed.
  • The form/dialog is aligned to bottom right of the same screen as the notify icon, whichever screen it is on.
  • When the focus is lost, the form will close.

I could try to implement all these behaviours. But if there's a standard windows control, I'd like to reuse it to get the same look and feel. Thanks.

Deling Ren
  • 87
  • 4
  • 1
    In WinForms, you already have the NotifyIcon component for that (which uses [Shell_NotifyIconW](https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shell_notifyiconw)). You can present anything you want when the status icon notifies an *interaction*. The rest is up to you (and you can implement ~whatever you please) -- `Screen.FromHandle()` gives you the current Screen and its WorkingArea. The `Activate` / `Deactivate` events... – Jimi Jul 25 '23 at 01:08

1 Answers1

0

You're looking for NotifyIcon.

You're then going to want to hook OnClick events and there you can use conditions to determine if it was a left click -> do something.

Example:

void onclick(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        // do something
    }
}

There's some useful tips and information in this thread aswell: How can I make a .NET Windows Forms application that only runs in the System Tray?

Jonathan
  • 685
  • 1
  • 10
  • 30
  • Thanks for the pointer. I'm aware of NotifyIcon. As for the form itself, I wonder if there's anything in Windows SDK to make it look and feel like the standard forms, such as the calendar or volume control popups? I could style the form myself, but I just thought I should reuse if there's existing APIs. Thanks. – Deling Ren Jul 25 '23 at 17:19
  • 1
    Ah I see, I interpreted your post as that you wanted a built-in class for a tray app. (might want to rephrase your question to focus more on the app-style part) – Jonathan Jul 26 '23 at 07:12