Bonjour à tous.
J'essaie actuellement de faire une application qui se logerait en tray lorsque la fenêtre principale serait réduite. Ayant une tray icon, j'ai eu envie de lui adjoindre un menu contextuel pour rendre mon application plus ergonomique. Mais je rencontre un problème qui m'embête beaucoup : En effet, lorsque l'on ouvre le menu contextuel avec le bouton droit sur la tray icon, une entitée vide apparaît dans la barre des tâches. Après moulte recherche, j'ai aperçu cette solution qui apparaissait partout :
I had the same problem. I could not find a way to achieve this without
using Reflection. This won't be officially supported, since it uses a
private method on the NotifyIcon class, but here's what I did (using an
anonymous method):
niMain.MouseClick += delegate( object sender, MouseEventArgs e )
{
if ( e.Button != MouseButtons.Right )
{
niMain.GetType().InvokeMember(
"ShowContextMenu",
BindingFlags.InvokeMethod|BindingFlags.Instance|BindingFlags.NonPublic,
null,
niMain,
null
);
}
};
Dans mon cas, j'ai :
this->notifyIcon->MouseClick += gcnew System::Windows::Forms::MouseEventHandler(this, &MainFrame::notifyIcon_MouseClick);
J'ai donc remplacé niMain par notifyIcon et ShowContextMenu par notifyIcon_MouseClick, mais celà ne fonctionne pas. Quelqu'un pourrait-il me dire comment cette portion de code fonctionne, ou s'il a une autre solution s'il vous plaît ?
Pour info, pour la notifyIcon j'utilise une NotifyIcon
et pour le menu contextuel j'utilise un ContextMenuStrip.
Merci d'avance.
Partager