WinForms Taskbar Icon - Click Event not firing
Posted
by Greycrow
on Stack Overflow
See other posts from Stack Overflow
or by Greycrow
Published on 2010-04-07T19:56:57Z
Indexed on
2010/04/07
20:03 UTC
Read the original article
Hit count: 567
I have created a non-form c# program that uses the NotifyIcon class.
The text "(Click to Activate)" shows up when I hover the mouse. So I am getting some events handled.
However, The "Click" event does not fire and the Context menu doesnt show up.
public class CTNotify
{
static NotifyIcon CTicon = new NotifyIcon();
static ContextMenu contextMenu = new ContextMenu();
static void Main()
{
//Add a notify Icon
CTicon.Icon = new Icon("CTicon.ico");
CTicon.Text = "(Click to Activate)";
CTicon.Visible = true;
CTicon.Click += new System.EventHandler(CTicon_Click);
//Create a context menu for the notify icon
contextMenu.MenuItems.Add("E&xit");
//Attach context menu to icon
CTicon.ContextMenu = contextMenu;
while (true) //Infinite Loop
{
Thread.Sleep(300); //wait
}
}
private static void CTicon_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Clicked!");
}
}
© Stack Overflow or respective owner