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的新手。
答案 0 :(得分:0)
我在这里发布了类似的问题: 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