VSTO Outlook 2007 加载项上下文菜单 CommandBarButton 单击事件
我需要在收件箱的上下文菜单中添加一个按钮。我这个工作正常。我需要弄清楚的是,在事件处理程序的实现中,如何确定单击了哪个项目?
private void AddIn_Startup(object sender, EventArgs e)
{
Application.ItemContextMenuDisplay += Application_ItemContextMenuDisplay;
}
private void Application_ItemContextMenuDisplay(CommandBar commandBar, Selection selection)
{
commandBar.Controls[1].BeginGroup = true; // add seperator before first menu
var cmdButtonCopy = (CommandBarButton)commandBar.Controls.Add(MsoControlType.msoControlButton, 1, Missing.Value, 1, Missing.Value);
cmdButtonCopy.Caption = "&Copy Message";
cmdButtonCopy.Click += cmdButtonCopy_Click;
}
private void cmdButtonCopy_Click(CommandBarButton ctrl, ref bool canceldefault)
{
// no sender/event args to determine which item was clicked ...
}
在 cmdButtonCopy_Click 事件处理程序中,我需要复制右键单击的特定项目,但我不知道如何判断单击了哪个项目。
I need to add a button to the context menu of the inbox. I have this working fine. What I need to figure out is in the implementation of the event handler how do I determine which item/items was clicked?
private void AddIn_Startup(object sender, EventArgs e)
{
Application.ItemContextMenuDisplay += Application_ItemContextMenuDisplay;
}
private void Application_ItemContextMenuDisplay(CommandBar commandBar, Selection selection)
{
commandBar.Controls[1].BeginGroup = true; // add seperator before first menu
var cmdButtonCopy = (CommandBarButton)commandBar.Controls.Add(MsoControlType.msoControlButton, 1, Missing.Value, 1, Missing.Value);
cmdButtonCopy.Caption = "&Copy Message";
cmdButtonCopy.Click += cmdButtonCopy_Click;
}
private void cmdButtonCopy_Click(CommandBarButton ctrl, ref bool canceldefault)
{
// no sender/event args to determine which item was clicked ...
}
In the cmdButtonCopy_Click event handler I need to copy the specific item that was right-clicked but I can't figure out how to tell which item was clicked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在 CommandBarButton 内使用 tag 属性
You can use tag property inside the CommandBarButton
我已经写了代码来解决您的问题,请看一下:
I have written the code to solve your issue have a look at it: