使用Windows应用程序vb.net在ms word中添加右键单击项 [英] Add right click item in ms word using Windows Application vb.net

查看:66
本文介绍了使用Windows应用程序vb.net在ms word中添加右键单击项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Iam使用VS 2010,我想使用vb.net在ms word中添加右键单击项。



我没有这个事件处理程序



Iam Using VS 2010 , i want to add Add right click item in ms word using vb.net.

I dont have this Event Handler

Private Sub ThisAddIn_Startup() Handles Me.Startup

End Sub 





i尝试了这个但没有工作



i tried this but not working

Dim cellbar As Office.CommandBar = Doc.Application.CommandBars("Cell")
       Dim button As Office.CommandBarButton = DirectCast(cellbar.FindControl(Office.MsoControlType.msoControlButton, 0, "MYRIGHTCLICKMENU"), Office.CommandBarButton)
       If button Is Nothing Then
           ' add the button
           button = DirectCast(cellbar.Controls.Add(Office.MsoControlType.msoControlButton, , , cellbar.Controls.Count, True), Office.CommandBarButton)
           button.Caption = "Refresh"
           button.BeginGroup = True
           button.Tag = "MYRIGHTCLICKMENU"
           ' button.Click += New Office._CommandBarButtonEvents_ClickEventHandler(AddressOf MyButton_Click)
       End If





专家,请给我建议以获得解决方案



提前致谢



Experts,Please give me suggestions to get a solution

Thanks in advance

推荐答案

_CommandBarButtonEvents_ClickEventHandler eventHandler;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            try
            {
                eventHandler = new _CommandBarButtonEvents_ClickEventHandler
				(MyButton_Click);
                Word.Application applicationObject =
			Globals.ThisAddIn.Application as Word.Application;
                applicationObject.WindowBeforeRightClick +=
		new Microsoft.Office.Interop.Word.ApplicationEvents4_
		WindowBeforeRightClickEventHandler(App_WindowBeforeRightClick);
            }
            catch (Exception exception)
            {
                MessageBox.Show("Error: " + exception.Message);
            }
        }





将其转换为vb。



convert it in vb.


这篇关于使用Windows应用程序vb.net在ms word中添加右键单击项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆