I have a program which puts an icon in the notification area and has a menu associated with it available by right clicking on the icon. I want the menu items to be selected by single left clicks but I also want the user to be able to single left click on the icon itself to do some other functionality.
Here's the problem - the single click on the menu first fires the notifyicon1_cli ck() routine and then the menuitem1_click () routine. How do I know in the notifyicon1_cli ck() whether it has been called from a menu click or a click on the icon itself?
the following piece of test code duplicates the problem
Here's the problem - the single click on the menu first fires the notifyicon1_cli ck() routine and then the menuitem1_click () routine. How do I know in the notifyicon1_cli ck() whether it has been called from a menu click or a click on the icon itself?
the following piece of test code duplicates the problem
Code:
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public NotInheritable Class Form1
Inherits System.Windows.Forms.Form
Private contextMenu1 As System.Windows.Forms.ContextMenu
Friend WithEvents menuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents notifyIcon1 As System.Windows.Forms.NotifyIcon
Private components1 As System.ComponentModel.IContainer
<System.STAThread()> _
Public Shared Sub Main()
System.Windows.Forms.Application.Run(New Form1)
End Sub 'Main
Public Sub New()
Me.components = New System.ComponentModel.Container
Me.contextMenu1 = New System.Windows.Forms.ContextMenu
Me.menuItem1 = New System.Windows.Forms.MenuItem
' Initialize contextMenu1
Me.contextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() _
{Me.menuItem1})
' Initialize menuItem1
Me.menuItem1.Index = 0
Me.menuItem1.Text = "E&xit"
' Set up how the form should be displayed.
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Text = "Notify Icon Example"
' Create the NotifyIcon.
Me.notifyIcon1 = New System.Windows.Forms.NotifyIcon(Me.components)
' The Icon property sets the icon that will appear
' in the systray for this application.
notifyIcon1.Icon = New Icon("myicon.ico")
' The ContextMenu property sets the menu that will
' appear when the systray icon is right clicked.
notifyIcon1.ContextMenu = Me.contextMenu1
' The Text property sets the text that will be displayed,
' in a tooltip, when the mouse hovers over the systray icon.
notifyIcon1.Text = "Form1 (NotifyIcon example)"
notifyIcon1.Visible = True
notifyIcon1.BalloonTipIcon = ToolTipIcon.Info
notifyIcon1.BalloonTipTitle = " this is the balloon title "
notifyIcon1.BalloonTipText = " this is the ballon tip text "
notifyIcon1.ShowBalloonTip(30)
End Sub 'New
Private Sub notifyIcon1_Click(ByVal Sender As Object, ByVal e As EventArgs) Handles notifyIcon1.Click
' Show the form when the user double clicks on the notify icon.
' Set the WindowState to normal if the form is minimized.
If (Me.WindowState = FormWindowState.Minimized) Then _
Me.WindowState = FormWindowState.Normal
' Activate the form.
Me.Activate()
End Sub
Private Sub menuItem1_Click(ByVal Sender As Object, ByVal e As EventArgs) Handles menuItem1.Click
' Close the form, which closes the application.
Me.Close()
End Sub
End Class 'Form1
Comment