By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,588 Members | 1,920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,588 IT Pros & Developers. It's quick & easy.

ContextMenuStrip from a left click on a Notify Icon

P: n/a
I've written an application that can minimize to the tray and can reappear if
you double click on the icon in the tray (ShowInTaskbar is set to false).
I've also created a ContextMenuStrip (Visual C# 2005) so that you can write
click on the icon in the tray for options. I then captured the event for
mouse clicks on the Notify Icon so that I could detect the left click event
and then display the contextmenustrip using either:
contextMenuStrip1.Show(this,
this.PointToClient(Cursor.Position));
or:
contextMenuStrip1.Show(this.PointToClient(Cursor.P osition));

This works well and displays the contextmenustrip appropriately, however
whilst doing this it also creates an icon for the application in the taskbar
which isn't intended as the form has been set to ShowInTaskbar = false. I've
also tried using a dummy control as the parameter to show to no avail.
Feb 26 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi Simon,

I performed a test based on your description and did see the problem.

I also performed a test on ContextMenu and found that the problem doesn't
exist on ContextMeu. So it looks to me like a limitation of
ContextMenuStrip.

I have searched in our inner database. However, I didn't find a similar
issue in it.

As for a workaround, I think you have two options.

One option is to use ContextMenu intead of ContextMenuStrip.

The other is to set the ContextMenuStrip property of the NotifyIcon to the
ContextMenuStrip on your form. Thus, you could show up the ContextMenuStrip
by right-clicking the NotifyIcon in the system tray.

Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 27 '07 #2

P: n/a
Hi Linda,
Many thanks for your response. Unfortunately I am already using the
ContextMenuStrip property of the Notify Icon but as you state this only works
for right clicks and not also for left clicks hence the addtional code I
spoke of.

Do you know if there are any plans for Microsoft to fix this bug or do you
know if there are any other work arounds? If I remember correctly, by using
just ContextMenu instead you don't get the Office 2003 style menus.

Thanks
Feb 27 '07 #3

P: n/a
Hi Simon,

Thank you for your prompt response.

I will report this issue to our product team to ask if there's a better
workaround. And I will get the result back to you ASAP. I appreciate your
patience.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 28 '07 #4

P: n/a
Hi Simon,

I received a response from our product team. The following is the response
I received.

The reason it works as a ContextMenu and not when Show is just called is
that the NotifyIcon p/invokes SetForgroundWindow before showing its
ContextMenu. To get this behavior, the user would have to do the same and
p/invoke SetForegroundWindow in the notifyIcon1_Click EventHandler:

using System.Runtime.InteropServices;

[DllImport("User32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern bool SetForegroundWindow(HandleRef hWnd);

void notifyIcon1_Click(object sender, EventArgs e)
{
SetForegroundWindow(new HandleRef(this, this.Handle));

this.contextMenuStrip1.Show(this, this.PointToClient(Cursor.Position));
}

I have tested the above code on my machine and confirmed it works.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

Mar 7 '07 #5

P: n/a
Hi Simon,

How about the problem now?

If the problem is still not solved, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

Mar 9 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.