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的新手。
发布于 2017-10-04 23:42:52
我在这里发布了一个类似的问题: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 Subhttps://stackoverflow.com/questions/45159123
复制相似问题