open menu when right click on notifyicon vb.net

how do i open a menu to exit the application when i right click on notifyicon in the systemtray? thanks.
StewSupportAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
wellholeConnect With a Mentor Commented:
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
 
wellholeCommented:
Add a contextmenu to the click handler for the icon.
0
 
StewSupportAuthor Commented:
how do i add the context menu to the icon?
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
wellholeCommented:
   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
 
StewSupportAuthor Commented:
YourExitHandler not sure what this will be please help
0
 
wellholeCommented:

Private Sub YourExitHandler(ByVal sender As Object, ByVal e As EventArgs)
  Application.Exit()
End Sub
0
 
StewSupportAuthor Commented:
that doesn't pop up any menu.
0
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
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
 
StewSupportAuthor Commented:
oh no i meant to give wellhole the point.
0
 
StewSupportAuthor Commented:
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
All Courses

From novice to tech pro — start learning today.