如何拦截内置Office Ribbon控件的点击 [英] How to intercept clicking of a built-in Office Ribbon control

查看:184
本文介绍了如何拦截内置Office Ribbon控件的点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以检测用户何时点击Excel中的页眉/页脚按钮,以便我可以在我的加载项选项卡上显示一些自定义页眉/页脚相关的功能区控件,并在用户不显示时隐藏它们在页眉/页脚编辑模式。

I'm wondering if it's possible to detect when a user has clicked the Header/Footer button in Excel so I can show some custom header/footer related ribbon controls on my add-in's tab and hide them when the user is not in header/footer edit mode.

有可能劫持这个按钮点击某种方式吗?我以前看过应用程序劫持Excel Save。我正在使用页眉/页脚按钮寻找类似的行为。

Is it possible to hijack this button click somehow? I've seen applications hijack the Excel Save before. I'm looking for similar behavior just with the header/footer button.

我正在使用C#,Visual Studio 2012和Excel 2010.我已经使用功能区XML方法创建了自定义功能区。

I'm using C#, Visual Studio 2012 and Excel 2010. I've created my custom ribbon using the Ribbon XML approach.

推荐答案

我发现工作的一种方法是使用功能区XML中的< commands> 部分(我不知道存在)。显然,这种机制允许您重新定义Excel内在的动作,但要注意并不是所有的控件都支持重新使用onAction回调)

One way I've discovered that worked was to use the <commands> section in the Ribbon XML (which I didn't know existed.) Apparently this mechanism allows you to re-purpose actions intrinsic to Excel but beware that not all controls support re-purposing the onAction callback)

<?xml version="1.0" encoding="UTF-8"?>
<customUI onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2006/01/customui">
    <commands>
        <command idMso="HeaderFooterInsert" onAction="testHeaderFooter"/>
    </commands>
  <ribbon>
    <tabs>...

以及相关的事件处理程序:

along with the associated event handler:

    public void testHeaderFooter(Office.IRibbonControl control, bool cancelDefault)
    {
        MessageBox.Show("Testing.");
        cancelDefault = false;
    }

此链接非常有帮助:

http://social.msdn.microsoft.com/Forums/office/en-US/e1a60d16-053e- 4697-b17c-b22d602f0400 /截图-a-gallery-of-a-gallery-of-excel-2007-ui-ribbon?forum = vsto

这篇关于如何拦截内置Office Ribbon控件的点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆