0

I am trying to show a context menu when i click on the tray icon (mnuLeft for left click and mnuRight for right click)

   Private Sub NotifyIcon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrayIcon.Click
      If e.Equals(MouseButtons.Left) Then
         TrayIcon.ContextMenuStrip = mnuLeft
      ElseIf e.Equals(MouseButtons.Right) Then
         TrayIcon.ContextMenuStrip = mnuRight
      End If
      TrayIcon.ContextMenuStrip.Show(Control.MousePosition) 'or ContextMenuStrip.Show(Control.MousePosition)
   End Sub

and I get the following error (on the ContextMenuStrip.Show line): NullReferenceException was unhandled

Can anyone help me out, any alternatives are welcomed...

PS:

.Show(Cursor.Position) >> same error

e.location >> Error 1 'location' is not a member of 'System.EventArgs'

Remus Rigo
  • 1,454
  • 8
  • 34
  • 60

2 Answers2

0

Should you be doing:

TrayIcon.ContextMenuStrip.Show(Control.MousePosition)
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
pingoo
  • 2,074
  • 14
  • 17
0
TrayIcon.ContextMenuStrip=mnuLeft

I set the ContextMenuStrip property of the NotifyIcon component and this time worked. Strage, first time it shown no menu, so I removed it, I guess I was too focused on the position and I forgot about this

Remus Rigo
  • 1,454
  • 8
  • 34
  • 60