Context menu not working on a NotifyIcon object

N

nic

I'm working on coding my first windows service. I'm trying to use a
NotifyIcon with a context menu for configuration of the form. The icon is
showing up in the taskbar of the system, but the context menu is not
working. Here's my OnStart event handler in the service:

protected override void OnStart(string[] args)
{
m_TrayIcon = new NotifyIcon();
m_TrayIcon.Icon =
new System.Drawing.Icon (@"C:\projects\Icons\toybox\RUBIC01F.ICO");

m_TrayIcon.Text = "Test Service Icon";

//Build the context menu:
m_TrayIcon.ContextMenu= new ContextMenu();
m_TrayIcon.ContextMenu.MenuItems.Add("Something");

m_TrayIcon.Visible = true;
}

Am I missing something here?

Thanks for any help!

Nic

PS if there is a more appropriate group to post this question to, please let
me know.
 
N

nic

I did a little more investigation, and it looks like the NotifyIcon isn't
getting any click events at all. I have this:

protected override void OnStart(string[] args)
{
m_TrayIcon = new NotifyIcon();
m_TrayIcon.Icon =
new System.Drawing.Icon (@"C:\projects\Icons\toybox\RUBIC01F.ICO");

m_TrayIcon.Text = "Test Service Icon";
//Build the context menu:

m_TrayIcon.ContextMenu= new ContextMenu();
m_TrayIcon.ContextMenu.MenuItems.Add("Something");
m_TrayIcon.Click+=new EventHandler(m_TrayIcon_Click);
m_TrayIcon.Visible = true;
}

private void m_TrayIcon_Click(object sender, EventArgs e)
{
MessageBox.Show("You clicked me!");
}

.... When I click (left or right) on the system tray icon nothing happens.
Any suggestions?
 
R

Robert Lofthouse

I have exactly the same problem, it goes even as far as no mouse events
firing on the notifyicon at all. Almost as if all event handling for the
notifyicon gets switched off as soon as it is invoked through a windows
service.

Perhaps this is where the focus should be in solving this problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top