ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> DevelopMentor-dotNET
DevelopMentor-dotNET
Re: [DOTNET] (SOLUTION) Question: How to show a menu on a NotifyIcon when the user clicks (left, once)?
by Ed Stegman other posts by this author
Nov 24 2001 12:10AM messages near this date
Re: [DOTNET] (SOLUTION) Question: How to show a menu on a NotifyIcon when the user clicks (left, once)? | Re: [DOTNET] Programmatically accessing Webform HTML
Actually, a large number of tray applets show context menus on left clicks. Another one from
 MSFT that does so is ActiveSync.
(Applet used to sync up a handheld like the pocket pc.)

Personally, I prefer the behavior of showing context menu on r/click, show a small subset of
 the GUI (most used feature) on l/click,
show full GUI on dbl/click. This is the exact behavior found of the taskbar volume control.

As a note, ICQ lets you map which mouse button fires the context menu. Which is ultimately t
he correct way to do things. Let the
user decide. :-))

Keep Smilin'
Ed Stegman

P.S. Nice job Mitch.

-----Original Message-----
From:John Lam

Actually, this behavior is "broken" in MSN Messenger as well. Left-click
results in a context menu appearing there as well - perhaps to keep
things consistent with ICQ users???

While I whole-heartedly support hacking into stuff on principle ;), the
problem that I see with your approach is that it would require
ReflectionPermission, which is at odds (somewhat) with dynamic code
download of WinForms.

I think MS really should add this to their list of minor warts on the
framework that should be addressed in V.Next.

-John


-----Original Message-----
From: Mitch Denny [mailto:mitch.denny@[...].COM]
Sent: Friday, November 23, 2001 6:37 PM
To: DOTNET@[...].COM
Subject: Re: [DOTNET] (SOLUTION) Question: How to show a menu on a
NotifyIcon when the user clicks (left, once)?

Thomas,

After a little bit of digging I found a fairly straight-forward
way of achieving the results that you desire. As others have
hinted at, you need to use reflection to get at the internals
of the NotifyIcon class.

Specifically the "ShowContextMenu" needs to be invoked, its
private so you will need to use the "InvokeMember" method on a
Type instance pointing to it. Let me illustrate in code:

        public void ni_Click(object sender, EventArgs e) {

                // Declare locals.
                NotifyIcon eventSource = null;
                Type niHandle = null;

                // Cast the event sender back to a NotifyIcon
                // for the sake of convienience.
                eventSource = (NotifyIcon)sender;

                // Get the type instance from the NotifyIcon.
                niHandle = eventSource.GetType();

                // Invoke the private ShowContextMenu method.
                niHandle.InvokeMember(
                        "ShowContextMenu",
                        BindingFlags.Instance |
                        BindingFlags.NonPublic |
                        BindingFlags.InvokeMethod,
                        null,
                        eventSource,
                        null
                        );

        }

The above code is the event handler that is registered with
the Click event on your NotifyIcon instance. Doing it this
way you avoid having to play with the native methods and
structures - just simply reuse the work that Microsoft
has done.

I would argue that creating this behavior on the left
mouse click works against the norms of the Windows user
interface, although it is a rule that is commonly broken
by products like ICQ - so you would be in good company.

Thomas, I was reluctant to answer your question or devote
serious time to researching it, but it appears that others
are in need of this NotifyIcon characteristic. I want you
to know that I am doing it for their benefit, and the benefit
of the archives, not yours.

Personally I found your responses to others who were trying
to help you on this list appauling, as you already know
since I e-mailed you privately.

I would also suggest that Microsoft didn't address this
in their factoring because it would promote an inconsistent
user experience.

----------------------------------------
- Mitch Denny
- http://www.warbyte.com
- mitch.denny@[...].com
- +61 (414) 610-141
-

>  -----Original Message-----
>  From: dotnet discussion [mailto:DOTNET@[...].COM]
>  On Behalf Of Thomas Tomiczek
>  Sent: Friday, 23 November 2001 8:02 PM
>  To: DOTNET@[...].COM
>  Subject: [DOTNET] Question: How to show a menu on a
>  NotifyIcon when the user clicks (left, once)?
> 
> 
>  Stimple question - I see this behaviour pretty often when the user is
>  clicking on the NotifyIcon (left OR right), the ContextMenu is opening
>  :-)
> 
>  Sadly - how the *** can I open a menu (the context menu) there? I have
>  no clue about the position where the NotifyIcon is visible,
>  and have no
>  access to it's Component. When I left-click on the
>  NotifyIcon, I always
>  get a MouseDown even with the coordinates X=0, Y=0.
> 
>  Anyone solved this? Sounds like a small design error here.
> 
>  Thomas Tomiczek
>  THONA Consulting Ltd.
>  Microsoft MVP (.NET / C#)
> 
>  You can read messages from the DOTNET archive, unsubscribe
>  from DOTNET, or
>  subscribe to other DevelopMentor lists at http://discuss.develop.com.
> 

You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.
Thread:
John Lam
Mitch Denny
Ed Stegman

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved