1
我想添加一些按鈕(也許其他類型的控件 - 我不知道現在)上下文菜單,但只有在滿足一些條件的情況下。所以,有可用的Application.WindowBeforeRightClick事件,但它只在單擊幻燈片時觸發,而不是在單擊某些形狀時觸發。PowerPoint + VSTO動態更改上下文菜單
到目前爲止,我加了一些XML作爲一個帶狀:
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<contextMenus>
<contextMenu idMso="ContextMenuShape">
<button id="button1" label="button1"/>
</contextMenu>
<contextMenu idMso="ContextMenuObjectsGroup">
<button id="button2" label="Align vertical axes" onAction="AlignXAxis" getVisible="ChangeCMObjectsGroupVisibility"/>
<button id="button3" label="Align horizontal axes" onAction="AlignYAxis" getVisible="ChangeCMObjectsGroupVisibility"/>
<button id="button4" label="Align scale" onAction="MaxScale" getVisible="ChangeCMObjectsGroupVisibility"/>
<button id="button5" label="Add legend" onAction="Legend" getVisible="ChangeCMObjectsGroupVisibility"/>
<button id="button6" label="Adjust chart width" onAction="AdjustWidth" getVisible="ChangeCMObjectsGroupVisibility"/>
<button id="button7" label="Adjust chart height" onAction="AdjustHeight" getVisible="ChangeCMObjectsGroupVisibility"/>
</contextMenu>
</contextMenus>
</customUI>
和代碼:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Application.WindowBeforeRightClick += new PPT.EApplication_WindowBeforeRightClickEventHandler(Application_WindowBeforeRightClick);
ribbon= (Ribbon1)CreateRibbonExtensibilityObject();
}
void Application_WindowBeforeRightClick(PPT.Selection Sel, ref bool Cancel)
{
PPT.Selection selection= Globals.ThisAddIn.Application.ActiveWindow.Selection;
if (selection.Type==PPT.PpSelectionType.ppSelectionShapes)
{
if (selection.ShapeRange.HasChart==MsoTriState.msoTrue)
{
ribbon.TurnOnChangeCMObjectsGroupVisibility();
}
}
}
是否可以檢查類型選擇形狀,隱藏/顯示/添加/刪除的控制和然後顯示正確的上下文菜單