Question on context menus

J

John Savidge

I have the following code in a class in my simple forms application, its in
the early stages. I am a VB.net newbie and have a question I am hoping
someone could help me on.

Assuming I know how to distinguish between left and right mouse clicks, how
do I access the click events of the contect menu I have added to my
notification icon? At the moment simply clicking the notification icon will
show / hide the form or start a new instance of the form if the user exits
the form.

Class1 is my startup object.

TIA

John

My code is below...

Public Class Class1

Private WithEvents nI As Windows.Forms.NotifyIcon
Private WithEvents cM As Windows.Forms.ContextMenu
Private m_frm As New frmsysmanager

Shared Sub Main()
Dim objClass1 As New Class1
Windows.Forms.Application.Run()
End Sub

Sub New()
MyBase.New()
Dim resources As Resources.ResourceManager = New
Resources.ResourceManager(GetType(Class1))
nI = New Windows.Forms.NotifyIcon
cM = New Windows.Forms.ContextMenu
nI.Icon = CType(resources.GetObject("NotifyIcon1.Icon"),
System.Drawing.Icon)
nI.Visible = True
cM.MenuItems.Add("Open Window")
cM.MenuItems.Add("Minimise to Tray")
nI.ContextMenu = cM
End Sub

Private Sub nI_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles nI.Click
If m_frm Is Nothing OrElse m_frm.IsDisposed Then
m_frm = New frmSysManager
Else
With m_frm
If .Visible = True Then
..Hide()
Else
..Show()
..Focus()
End If
End With
End If
End Sub
End Class
 
O

One Handed Man [ OHM# ]

Examples Below - Regards -OHM


To Add a Menu and Show it
ContextMenu1.MenuItems.Add("Add", AddressOf popUp_Click)

ContextMenu1.Show(DirectCast(sender, Control), New Point(e.X, e.Y))



To Handle The Selection

Private Sub popUp_Click(ByVal sender As Object, ByVal e As System.EventArgs)

If DeletingRows Then Exit Sub

'Debug.WriteLine("dgEvents_MouseUp")

Dim cc, sp As Point

Dim cmi As MenuItem

Dim TR As DataRow

Dim DT As DataTable

Dim DeleteCmd As New OleDbCommand



cmi = DirectCast(sender, MenuItem)

Select Case cmi.Text



John said:
I have the following code in a class in my simple forms application,
its in the early stages. I am a VB.net newbie and have a question I
am hoping someone could help me on.

Assuming I know how to distinguish between left and right mouse
clicks, how do I access the click events of the contect menu I have
added to my notification icon? At the moment simply clicking the
notification icon will show / hide the form or start a new instance
of the form if the user exits the form.

Class1 is my startup object.

TIA

John

My code is below...

Public Class Class1

Private WithEvents nI As Windows.Forms.NotifyIcon
Private WithEvents cM As Windows.Forms.ContextMenu
Private m_frm As New frmsysmanager

Shared Sub Main()
Dim objClass1 As New Class1
Windows.Forms.Application.Run()
End Sub

Sub New()
MyBase.New()
Dim resources As Resources.ResourceManager = New
Resources.ResourceManager(GetType(Class1))
nI = New Windows.Forms.NotifyIcon
cM = New Windows.Forms.ContextMenu
nI.Icon = CType(resources.GetObject("NotifyIcon1.Icon"),
System.Drawing.Icon)
nI.Visible = True
cM.MenuItems.Add("Open Window")
cM.MenuItems.Add("Minimise to Tray")
nI.ContextMenu = cM
End Sub

Private Sub nI_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles nI.Click
If m_frm Is Nothing OrElse m_frm.IsDisposed Then
m_frm = New frmSysManager
Else
With m_frm
If .Visible = True Then
.Hide()
Else
.Show()
.Focus()
End If
End With
End If
End Sub
End Class

Regards - OHM# (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top