关于 .net:Office Powerpoint Ribbon 菜单项访问? | 珊瑚贝

Office Powerpoint Ribbon menu item access?


是否可以从 Powerpoint 幻灯片中访问功能区菜单项?
例如,我在功能区菜单下有一个复选框。现在我希望当我点击一个形状时,这个复选框应该被选中?

这个问题似乎很简单,但我找不到解决方法。你有什么主意吗?
(在 C# 中首选)

enter

用代码编辑

自定义功能区菜单

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”;
}

我认为您必须为此使用 Application.WindowSelectionChange 事件。

根据 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.

它会给你一个 Selection 对象,你可以进一步使用它。

事件处理程序的签名:

1
void (Microsoft.Office.Interop.PowerPoint.Selection selection)
  • 选择事件对我来说不是问题。我的问题是当我们捕捉到选择事件时,是否可以更新功能区菜单项?就像将复选框(在功能区菜单下)的值从 false 更改为 true?
  • 我试图访问功能区菜单并更新复选框,更改其选中值,更改其标签,但它没有改变任何东西
  • @chipbk10:什么复选框?我在您的(不存在的)代码中没有看到复选框。
  • @chipbk10:我会试一试,然后回来找你。
  • 总体思路是让功能区或控件的 onLoad 事件将对自身的引用传递给代码中的例程;然后根据需要,您的代码调用是控件的无效方法;然后控件会查询您的代码以获取诸如”我是否检查过?”之类的值。 Martin/Puls/Hennig RibbonX 这本书有这方面的 VBA 示例(我想我在另一个线程中向你提到了这本书)。
  • 我仍在使用标准功能区菜单,没有时间转换为 RibbonX。那么使用标准功能区菜单,就不可能在运行时访问它的项目吗?


来源:https://www.codenong.com/22458137/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9320.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?