Probl�me avec un ContextMenuStrip et un NotifyIcon
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.