开发者

onclick delegate is triggered only once

I am writing an outlook add-in that adds a menu to outlook. Although I set delegate to an action for the menu it seems like it is being removed after one call to the delegate - one click on the menu item. next time user clicks it is not getting开发者_StackOverflow社区 to my delegate. code example:

menuCommand = (Office.CommandBarButton)cmdBarControl.Controls.Add(
Office.MsoControlType.msoControlButton, missing, missing, missing, true);

menuCommand.Caption = "&Generate weekly...";
menuCommand.Tag = "Generate";
menuCommand.FaceId = 65;

menuCommand.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(
menuCommand_Generate_Click);

menuCommand = (Office.CommandBarButton)cmdBarControl.Controls.Add(
    Office.MsoControlType.msoControlButton, missing, missing, missing, true);

menuCommand.Caption = "&About";
menuCommand.Tag = "About";
menuCommand.FaceId = 65;

menuCommand.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(
menuCommand_About_Click);
menuCommand.BeginGroup = true;

What should I do in order for the menu to trigger the action every time?


Is menuitem a local variable? , becouse then the garbage collector might clean in up once it falls out of scope.

Try keeping the variable in a global object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜