Solved

open menu when right click on notifyicon vb.net

Posted on 2009-05-18
11
1,802 Views
Last Modified: 2012-05-07
how do i open a menu to exit the application when i right click on notifyicon in the systemtray? thanks.
0
Comment
Question by:StewSupport
  • 5
  • 4
11 Comments
 
LVL 9

Expert Comment

by:wellhole
ID: 24414199
Add a contextmenu to the click handler for the icon.
0
 

Author Comment

by:StewSupport
ID: 24414219
how do i add the context menu to the icon?
0
 
LVL 9

Expert Comment

by:wellhole
ID: 24414265
   Private Sub Icon_MouseUp(ByVal sender As Object, ByVal e As EventArgs) Handles icon.MouseUp
        icon.ContextMenu = New ContextMenu
        icon.ContextMenu.MenuItems.Add("Close", AddressOf YourExitHandler)
    End Sub
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:StewSupport
ID: 24414366
YourExitHandler not sure what this will be please help
0
 
LVL 9

Expert Comment

by:wellhole
ID: 24414391

Private Sub YourExitHandler(ByVal sender As Object, ByVal e As EventArgs)
  Application.Exit()
End Sub
0
 

Author Comment

by:StewSupport
ID: 24414439
that doesn't pop up any menu.
0
 
LVL 9

Accepted Solution

by:
wellhole earned 400 total points
ID: 24414598
It should, but perhaps you'll want to put this in your Load handler instead of using the MouseUp handler.

Sub Form_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        icon.ContextMenu = New ContextMenu
        icon.ContextMenu.MenuItems.Add("Close", AddressOf YourExitHandler)
End Sub
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 100 total points
ID: 24415116
Add a ContextMenuStrip to your Form and then add an Item called "Close" to the Menu.  Now select your NotifyIcon and change the ContextMenuStrip property to point to your ContextMenuStrip.  Double Click the "Close" item in the menu and add "Me.Close()" to the code stub.

See the code and Images below:
Public Class Form1
 
    Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
        Me.Close()
    End Sub
 
End Class

Open in new window

ContextMenuCloseExample.jpg
0
 

Author Comment

by:StewSupport
ID: 24415243
oh no i meant to give wellhole the point.
0
 

Author Comment

by:StewSupport
ID: 24415300
i sent email to ask if i can reassign point but in case if they don't answer, can i just create new question and just give you the point? thanks.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

815 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now