Handling a Click Event On a System Tray Icon
Solution Available
Michael W.
Lititz, PA

Jan 13, 2009
30 Posts

Handling a Click Event on a System Tray Icon

I have some simple code that puts an icon in the System Tray.

    nIcon = new NotifyIcon()
    nIcon.Icon = new System_Drawing.Icon(sIconLocation)
    nIcon.Text = sHoverText
    nIcon.Visible = True

When the user right clicks or double clicks on the icon, nothing currently happens.  How do I incorporate these click events into my code?  Thanks

Amit G.
Irvine, CA

Jan 13, 2009
26 Posts

Re: Handling a Click Event on a System Tray Icon

I have attached a sample program to this incident demonstrating the use of the NotifyIcon .NET class along with its OnClick Event. A .NET event can be linked to an ATEasy procedure by using the following code:

AddHandler nIcon.OnClick, OnClickEvent

In this case, OnClickEvent is an ATEasy procedure.

You can modify the example code (attached to this thread) to link other events such as OnDoubleClick.


File Attachment:
SystemIcon.zip

Michael W.
Lititz, PA

Jan 13, 2009
30 Posts

Re: Handling a Click Event on a System Tray Icon

That works.  Thanks!

Michael W.
Lititz, PA

Jul 7, 2009
30 Posts

Re: Handling a Click Event on a System Tray Icon

At the time, this worked.  But ever since getting .NET Framework updates, it doesn't work.  Try running the SystemIcon program now.  When you click on the icon, you will get the attached error.  I currently have .NET Framework 3.5 SP1 installed on Win XP Pro Ver 2002 SP3.  Can you please help to fix it.  I can't seem to make any sense out of it.  Thanks.


File Attachment:
NET Framework error.bmp

Amit G.
Irvine, CA

Jul 8, 2009
26 Posts

Re: Handling a Click Event on a System Tray Icon

What version and build of ATEasy are you using? I have Vista installed with .NET 3.5 SP1 and the SystemIcon ATEasy example works fine for me. Are you able to use other .NET classes? Can you step through the SystemIcon code and find the exact line that causes the error you experience?

Michael W.
Lititz, PA

Jul 13, 2009
30 Posts

Re: Handling a Click Event on a System Tray Icon

I am using ATEasy 7, Build 142b.  It's not a line of code that is causing the problem; it happens when I click on the icon that is put in the System Tray.  I put a breakpoint on the first line of the OnClickEvent() procedure, but it doesn't break there.  I get the error instead.  I ran the program on 3 computers (all Win XP Pro with .NET 3.5 SP1) and I get the same error on all of them.  We don't have any computers running Vista so I can't try the program on Vista.  Try it on a Win XP computer please.

Amit G.
Irvine, CA

Jul 13, 2009
26 Posts

Re: Handling a Click Event on a System Tray Icon

We are able to replicate the issue on WinXP and Vista when the Icon is clicked. This appears to be an issue with some change in .NET 3.5 and the way we implement the AddHandler ATEasy statement. We will get back to you regarding a solution.

Amit G.
Irvine, CA

Jul 14, 2009
26 Posts

Re: Handling a Click Event on a System Tray Icon

We have a fix for this issue and it will be included in the next build/version of ATEasy.

.NET 3.5 changed the way events were assigned to handlers. You can work around this issue by uninstalling .NET 3.5 and use 3.0 instead.

Or you could create your own .NET assembly wrapper that deals with the NotifyIcon OnClick event and calls your ATEasy procedure (pass in an ATEasy procedure as a delegate parameter). An example of this can be found in the ATEasy DotNet example project in the "CallBack" test.

Michael W.
Lititz, PA

Jul 15, 2009
30 Posts

Re: Handling a Click Event on a System Tray Icon

Uninstalling .NET 3.5 from 50+ computers is impractical and I don't have the time to create my own .NET assembly wrapper.  So, when is the next build/version coming out?  By the way, you may want to run the DotNet example project--Test 1.5 failed.

Amit G.
Irvine, CA

Jul 15, 2009
26 Posts

Re: Handling a Click Event on a System Tray Icon

We can provide you with an updated ATEasy in 1-2 weeks. We will make an official release after that.



Please Note
You need to have a M@GIC account to participate in the Forums.
Not yet registered on our website? Click here to register today!

All content, information and opinions presented on the Marvin Test Solutions User Forums are those of the authors of the posts and messages and not Marvin Test Solutions'. All attachments and files are downloaded at your own risk. [Read More]