Bonjour,

Ce message est en relation avec celui-ci :
http://www.developpez.net/forums/d67...tifyicon-form/

Voici donc le problème.

J'ai créé un NotifyIcon dans un Main() pour qu'il ne dépende pas d'une WinForm.

Je voudrais que le ContextMenuStrip associé à cette NotifyIcon soit ouverte sur un clique de souris (géré pour réagir au clique droit uniquement).

Le problème est que l'EventHandler ne semble pas réagir à mon clique sur l'icône.

Voici le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Imports System.Windows.Forms
Imports System.ServiceProcess
Imports System.Timers
 
Module myNotifier
    Private components As System.ComponentModel.IContainer
    Friend WithEvents myNotifyIcon As NotifyIcon
 
    <STAThread()> _
    Public Sub Main(ByVal args As String())
        components = New System.ComponentModel.Container
        Application.EnableVisualStyles()
 
        CreateNotifyIcon()
 
        Application.Run()
 
    End Sub
 
    Sub CreateNotifyIcon()
        Dim myNotifyIcon As New NotifyIcon
        myNotifyIcon = New NotifyIcon(components)
 
        Dim iconstop As New System.Drawing.Icon("NotifyIcon1.Ico")
 
        AddHandler myNotifyIcon.Click, AddressOf myNotifyIcon_MouseRightClick
        myNotifyIcon.ContextMenuStrip = myContextMenuStrip
        myNotifyIcon.Icon = iconstop
        myNotifyIcon.Text = "myProject"
        myNotifyIcon.Visible = True
 
    End Sub
 
    Private Sub myNotifyIcon_MouseRightClick(ByVal sender As System.Object, _
                                            ByVal e As MouseEventArgs) _
                                            Handles myNotifyIcon.MouseClick, myNotifyIcon.Click
        If e.Button = MouseButtons.Right Then
            myNotifyIcon.ContextMenuStrip = myContextMenuStrip
            myNotifyIcon.ContextMenuStrip.Show()
        End If
 
    End Sub
End Module
Il y a forcément une boulette quelque part...