【问题标题】:add event handler to Context menu Submenu in Vsto Vb.net将事件处理程序添加到 Vsto Vb.net 中的上下文菜单子菜单
【发布时间】:2017-12-22 20:52:15
【问题描述】:
 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

我已经构建了一个带有子菜单(PEG,XCCG)的上下文菜单,并且我已经为子菜单附加了事件处理程序。但是当我运行代码时,事件只为第一个事件 PEG 触发 请帮助我。我是 VSTO 的新手。

【问题讨论】:

  • 嗨,请帮帮我。

标签: c# vb.net vba vsto


【解决方案1】:

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

在这两行之后...

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

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

添加如下所示的一行

AddHandler XCCG.Click, AddressOf ButtonClick

AddHandler PEG.Click, AddressOf ButtonClick

这对我有用。 这是我的事件处理程序的一个示例,我只是使用标题来确定单击了哪个菜单。就我而言,这已经足够了。

Private Sub cb_Click(Ctrl As CommandBarButton, ByRef CancelDefault As Boolean) Handles cb.Click
        MsgBox(Ctrl.Caption, MsgBoxStyle.ApplicationModal, "Fast View")
    End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-20
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    • 2017-04-27
    • 2011-07-22
    • 1970-01-01
    相关资源
    最近更新 更多