If you want to handle commands in CAB you have to use the AddInvoker method, for example on a menu item you’d have
[csharp]
this.Commands["SomeName"].AddInvoker(menuItem, “Click”);
[/csharp]
The listening method should be decorated with the CommandHandler attribute
[csharp]
[CommandHandler("SomeName")]
public void HandleIt(object sender, EventArgs e)
{
MessageBox.Show(“Works!”);
}
[/csharp]
Now here come the crucial remark and it took me half a day to discover it…
hi,
In my project I found the this.Commands["SomeName"].AddInvoker(menuItem, “Click”); somewhat ackward.
The reason is that the control gets disabled when the commandstatus is disabled and hidden when unavailable.
If you just use the normal evenhandling delegates created by your view’s controls, this should work fine also.
The only reason why one should write such a signature is when you want to handle events genericaly. But then again you loose any rich eventhandler from implemented by your control.
I should’ve liked to see a method like :
this.Commands["SomeName"].AddInvoker(menuItem);
But he, that’s me!
By tim June 28, 2007 - 11:10 amHi
Lovely man, your views saved me, else I would have been shit. It really helped me a lot
Thanks a lot and may god always bless you for your good heart of sharing knowledge.
By Ram August 29, 2011 - 8:17 am