Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Activating ContextMenuStrip from a Icon's Tray.

Posted on 2006-05-19
10
Medium Priority
?
709 Views
Last Modified: 2008-01-09

Hello for all,

I had an application done in VB6, that created an Icon on the Window's Tray...
and when a mouse click on the icon a menu will appear.
In VB6 I used "PopUpMenu" that worked fine.

I upgraded the code to .NET using the same code for Tray (using Shell_NotifyIcon);
but for the Menu of course I have to use the ContextMenuStrip class -
that when a mouse click, it activates the MenuStrip after HIDING the main form:
menuStrip.Show(pnt)                      ' To locate the menu on "pnt" relative to screen
(Notice I use "menuStrip.Show(pnt)" to show it relatively to the screen and not "menuStrip.Show(Me, pnt)")

The problem here, that when menu got activated and opened I see its button, blank with
an empty icon on the taskbar! like I opened a new Form/Application.
Of course in normal situations where I activate the menu on some container I don't got this....

How can I make this not to appear anymore in the taskbar????

Thanks a lot in advance.




0
Comment
Question by:nazdaq
  • 5
  • 2
7 Comments
 
LVL 6

Expert Comment

by:willbdman
ID: 16716635
Why not use the .NET tray icon?

System.Window.Forms.NotifyIcon

you can then assigna  context menu to it, thus making life a lot easier for yourself, and it should (in theory) solve your problem.

Here some example code from one of my projects:-

       ' Stores icon file you want to display in tray
        Dim MyIcon As New System.Drawing.Icon("C:\MyIcon.ico")

        ' Tray Icon
        Dim MyTray As New System.Windows.Forms.NotifyIcon

        ' Context Menu
        Dim MyContext As New System.Windows.Forms.ContextMenu

        ' Add items to menu
        MyContext.MenuItems.Add("Item1")
        MyContext.MenuItems.Add("Item2")

        ' Set which context menu to use
        Me.icnArw.ContextMenu = MyContext

        ' Set Icon to show
        Me.icnArw.Icon = MyIcon

        ' Set hover text to show, when mouse moves over
        Me.icnArw.Text = "My Tray Icon"

        'Minimise this form
        Me.WindowState = FormWindowState.Minimized

        ' Hide this form
        Me.Hide()

        'Show icon in taskbar
        Me.icnArw.Visible = True
0
 

Author Comment

by:nazdaq
ID: 16716661

Thanks for replying...

In the example above you "MyTray"... you meant "icnArw" as a memeber of "Me" right?



0
 
LVL 6

Expert Comment

by:willbdman
ID: 16716802
Sorry, bodged editing im afraid!!

Should be:-

' Set which context menu to use
        MyTray.ContextMenu = MyContext

        ' Set Icon to show
        MyTray.Icon = MyIcon

        ' Set hover text to show, when mouse moves over
        MyTray.Text = "My Tray Icon"
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 6

Expert Comment

by:willbdman
ID: 16716806
missed another one...


'Show icon in taskbar
       MyTray.Visible = True
0
 

Author Comment

by:nazdaq
ID: 16716862

Thanks again,

but I have another question concerning this...

How can I link to it a specail event(s)?

Other than right-click to activate the MenuStrip, I want to customize
other events, double-click... for example????

0
 
LVL 6

Expert Comment

by:willbdman
ID: 16716968
Private Sub MyTray_DoubleClick(Sender as object, e as EventArgs) handles MyTray.DoubleClick

' Your code here

End Sub
0
 
LVL 6

Accepted Solution

by:
willbdman earned 1400 total points
ID: 16716972
Here are the available events, as taken from the MSDN:-

The events of the NotifyIcon class are listed here. For a complete list of NotifyIcon class members, see the NotifyIcon Members topic.

Public Events
Click Occurs when the user clicks the icon in the status area.

Disposed (inherited from Component) Adds an event handler to listen to the Disposed event on the component.

DoubleClick Occurs when the user double-clicks the icon in the status notification area of the taskbar.

MouseDown Occurs when the user presses the mouse button while the pointer is over the icon in the status notification area of the taskbar.

MouseMove Occurs when the user moves the mouse while the pointer is over the icon in the status notification area of the taskbar.

MouseUp Occurs when the user releases the mouse button while the pointer is over the icon in the status notification area of the taskbar.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month11 days, 13 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question