Solved

open menu when right click on notifyicon vb.net

Posted on 2009-05-18
11
1,782 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
Comment Utility
Add a contextmenu to the click handler for the icon.
0
 

Author Comment

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

Expert Comment

by:wellhole
Comment Utility
   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
 

Author Comment

by:StewSupport
Comment Utility
YourExitHandler not sure what this will be please help
0
 
LVL 9

Expert Comment

by:wellhole
Comment Utility

Private Sub YourExitHandler(ByVal sender As Object, ByVal e As EventArgs)
  Application.Exit()
End Sub
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:StewSupport
Comment Utility
that doesn't pop up any menu.
0
 
LVL 9

Accepted Solution

by:
wellhole earned 400 total points
Comment Utility
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
Comment Utility
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
Comment Utility
oh no i meant to give wellhole the point.
0
 

Author Comment

by:StewSupport
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

10 Experts available now in Live!

Get 1:1 Help Now