Office Powerpoint Ribbon menu item access?
是否可以从 Powerpoint 幻灯片中访问功能区菜单项?
例如,我在功能区菜单下有一个复选框。现在我希望当我点击一个形状时,这个复选框应该被选中?
这个问题似乎很简单,但我找不到解决方法。你有什么主意吗?
(在 C# 中首选)
用代码编辑
自定义功能区菜单
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public partial class RibbonMenu { private void RibbonMenu_Load(object sender, RibbonUIEventArgs e) { } public void ChangeCheckBox() { System.Windows.Forms.MessageBox.Show("The CheckBox is changed"); this.checkBox.Checked = true; this.checkBox.Label ="AAAAAAA" } } |
捕捉选择事件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | public partial class ThisAddIn { private RibbonMenu menu; private void ThisAddIn_Startup(object sender, System.EventArgs e) { CreateRibbonExtensibilityObject(); Application.WindowSelectionChange += new PowerPoint.EApplication_WindowSelectionChangeEventHandler(Application_WindowSelectionChange); } protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject() { this.menu = new RibbonMenu(); return Globals.Factory.GetRibbonFactory().CreateRibbonManager(new Microsoft.Office.Tools.Ribbon.IRibbonExtension[] { this.menu }); } private void Application_WindowSelectionChange(PowerPoint.Selection Sel) { //.... Check if the selection is a shape's selection this.menu.ChangeCheckBox(); } } |
结果是出现了"The CheckBox is changed"的消息框,但是该复选框没有被选中并且标签没有被更改为"AAAAAA"
使用全局访问 Office 功能区菜单项如下:
1 2 3 4 | private void Access_All_Ribbons_Globals() { Globals.Ribbons.Ribbon1.comboBox1.Text ="Hello World"; } |
我认为您必须为此使用
根据 MSDN:
Occurs when the selection of text, a shape, or a slide in the active document window changes, whether in the user interface or in code.
它会给你一个
事件处理程序的签名:
1 | void (Microsoft.Office.Interop.PowerPoint.Selection selection) |