首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将事件处理程序添加到Vsto Vb.net中的上下文菜单子菜单

将事件处理程序添加到Vsto Vb.net中的上下文菜单子菜单
EN

Stack Overflow用户
提问于 2017-07-18 14:30:20
回答 1查看 296关注 0票数 0
代码语言:javascript
运行
复制
 ProgramEngines = ContextMenu.Controls.Add(Type:=Office.MsoControlType.msoControlPopup, Before:=1)
                With ProgramEngines
                    .Caption = "Program Engines"
                    With .Controls.Add(Type:=Office.MsoControlType.msoControlPopup, Before:=1)
                        .Caption = "Gas"
                        For intCnt = 0 To colEngineData.Count - 1
                            If Strings.Split(colEngineData.Item(intCnt), "~")(0) = "Gas" Then
                                **PEG** = .Controls.Add(Type:=Office.MsoControlType.msoControlButton)
                                With PEG
                                    .Caption = Strings.Split(colEngineData.Item(intCnt), "~")(1)                                   
                                    .FaceId = 548
                                End With
                            End If
                        Next
                    End With

 XCCEngines = ContextMenu.Controls.Add(Type:=Office.MsoControlType.msoControlPopup, Before:=2)

                With XCCEngines
                    .Caption = "XCC Engines"

                    With .Controls.Add(Type:=Office.MsoControlType.msoControlPopup, Before:=1)
                        .Caption = "Gas"
                        For intCnt = 0 To colEngineDataXCC.Count - 1
                            If Strings.Split(colEngineDataXCC.Item(intCnt), "~")(0) = "Gas" Then
                                **XCCG** = .Controls.Add(Type:=Office.MsoControlType.msoControlButton)
                                With XCCG
                                    .Caption = Strings.Split(colEngineDataXCC.Item(intCnt), "~")(1)                                   
                                    .FaceId = 548
                                End With
                            End If
                        Next
                    End With


        Private Sub ButtonClick(ByVal ctrl As Office.CommandBarButton, ByRef Cancel As Boolean) Handles PEG.Click, XCCG.Click
            PutValue_Engine_Trans(ctrl.Caption)
        End Sub

我已经建立了一个上下文菜单与子菜单(聚乙二醇,XCCG),我已经附加了submenu.But的事件处理程序,当我运行的代码事件只触发第一个事件聚乙二醇,请帮助我在这。我是VSTO的新手。

EN

回答 1

Stack Overflow用户

发布于 2017-10-04 23:42:52

我在这里发布了一个类似的问题:Respond to Multiple VSTO Context Menus in VB.Net

在这两行之后...

代码语言:javascript
运行
复制
 **XCCG** = .Controls.Add(Type:=Office.MsoControlType.msoControlButton)

 **PEG** = .Controls.Add(Type:=Office.MsoControlType.msoControlButton)

添加一行代码,如下所示

代码语言:javascript
运行
复制
AddHandler XCCG.Click, AddressOf ButtonClick

AddHandler PEG.Click, AddressOf ButtonClick

这对我来说很有效。这是我的事件处理程序的一个例子,我只是用标题来确定哪个菜单被点击了。对我来说,这已经足够好了。

代码语言:javascript
运行
复制
Private Sub cb_Click(Ctrl As CommandBarButton, ByRef CancelDefault As Boolean) Handles cb.Click
        MsgBox(Ctrl.Caption, MsgBoxStyle.ApplicationModal, "Fast View")
    End Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45159123

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档