473,408 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

ContextMenuStrip from a left click on a Notify Icon

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
5 15419
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jm | last post by:
Hi, I have a C# program that changes the notifyIcon during the program. What I have noticed is that sometimes when the program is over the old icon will still be in the system tray. But when i...
1
by: Jake | last post by:
I'm having a problem with the ContextMenuStrip object when using it on a NotifyIcon while the taskbar is at the top of the screen. Problem: The context menu will draw above the top of the...
12
by: mdb | last post by:
My app has a notify icon in the systray. I want the left mouse click to initiate a menu, and a right-mouse click to do something else. Normally, for a button, I would listen to MouseDown and if I...
7
by: Dave | last post by:
How do I get my ContextMenuStrip to receive key down preview events? I have the event hooked but I don't see the key strokes in the event? Dave
0
by: Viper | last post by:
I added a NotifyIcon to my project and a ContextMenuStrip so that when the taskbar icon is clicked a menu shows up. I added the ContextMenuStrip to the properties menu for the notifyicon. now...
1
by: johnnypung | last post by:
I have a treeview opening a contextMenuStrip on right click. However the right click would not select the node that it right clicks on. How should I make it so the right click will select the node,...
9
by: =?Utf-8?B?Z2luYWNyZXNzZQ==?= | last post by:
Hi, I have a form (Form1) with a ContextMenuStrip (ContextMenuStrip1). If I pass Form1 to a Utility Sub with the following code: Public Sub Utility(theForm as Object) with theForm For Each...
2
by: eBob.com | last post by:
I've been working on an app which has an array of RichTextBoxes. And I have a context menu for the RTBs. The context menu has two levels; the first level has two items, "Load Sample Text File"...
1
by: \Ji Zhou [MSFT]\ | last post by:
Hello Jason, Thanks for using Microsoft Newsgroup Support Service, my name is Ji Zhou and I will be working on this issue with you. I have tried to but cannot reproduce your issue on my side....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.