Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2048
  • Last Modified:

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.
0
StewSupport
Asked:
StewSupport
  • 5
  • 4
2 Solutions
 
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
 
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
 
wellholeCommented:
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
 
Mike TomlinsonMiddle 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now