Re: [DOTNET] (SOLUTION) Question: How to show a menu on a
NotifyIcon when the user clicks (left, once)?
by Mitch Denny other posts by this author
Nov 24 2001 12:19AM messages near this date
Re: [DOTNET] (SOLUTION) Question: How to show a menu on a
NotifyIcon when the user clicks (left, once)?
|
Re: [DOTNET] (SOLUTION) Question: How to show a menu on a
NotifyIcon when
the user clicks (left, once)?
John,
Thanks for pointing out MSN Messenger, I guess this
is a situation where a convention established by ICQ
needs to carry to enhance usability.
Although I think it would have been better if the
left mouse click on the MSN messenger icon actually
brought up the actual Window, not the context menu,
but that is perrsonal preference - it does it on
the double click anyway.
With the reflection permission stuff. I can see how
this might become an issue, but I think that in 90%
of the scenarios the NotifyIcon would be handled
by the bootstraping application that downloads the
code dynamically.
Mind you if 10% of developers are going to find
it useful then they may as well do it, maybe have
two properties:
NotifyIcon.Menu (left button)
NotifyIcon.ContextMenu (right button)
Naturally, this would flip when alternative button
configurations were used. Its not a mega issue for
me but I can appreciate the concerns you might have.
----------------------------------------
- Mitch Denny
- http://www.warbyte.com
- mitch.denny@[...].com
- +61 (414) 610-141
-
> -----Original Message-----
> From: dotnet discussion [mailto:DOTNET@[...].COM]
> On Behalf Of John Lam
> Sent: Saturday, 24 November 2001 10:37 AM
> To: DOTNET@[...].COM
> Subject: Re: [DOTNET] (SOLUTION) Question: How to show a menu
> on a NotifyIcon when the user clicks (left, once)?
>
>
> 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
|