简体   繁体   中英

How can I create my own events in my C# application like the default ones available?

I needed to update the system tray icon's text value, of my application, whenever a user hovers over it. I noticed that no such event exists for system tray icons. Is it possible to create a hover event for a system tray icon and if so how can I go about accomplishing it?

How about hooking into NotifyIcon.MouseMove ?

As a basic example, this seems to work (with a NotifyIcon on a Form ):

    public Form1() {
        InitializeComponent();
        notifyIcon1.MouseMove += delegate
        {
            notifyIcon1.Text = DateTime.Now.TimeOfDay.ToString();
        };
        notifyIcon1.Icon = SystemIcons.Hand;
        notifyIcon1.Visible = true;            
    }

In WPF, UI Elements have a ToolTipOpening/ToolTipClosing event. You should update the tooltip text in the opening. I don't know if system tray icons have such behavior, but i guess there is something similar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM