获取 Outlook 后台的复选框状态?

发布于 2024-11-17 10:40:59 字数 2264 浏览 3 评论 0原文

使用 Outlook 2010:如果我在 XML 中定义了一个复选框供后台加载,我如何查询该元素并使用 C# 获取其状态?下面是后台 XML 的示例:

<?xml version="1.0" encoding="utf-8"?>
<customUI onLoad="Ribbon_Load"
          xmlns="http://schemas.microsoft.com/office/2009/07/customui">
  <backstage>
    <tab id="MyBackstageTab"
         getVisible="MyBackstageTab_GetVisible">
      <firstColumn>
        <group id="RegularGroup">
          <bottomItems>
            <groupBox id="GeneralGroupBox">

              <!-- This works fine; onAction is called every click. -->
              <button id="ApplyButton"
                      label="Apply"
                      onAction="ButtonAction"/>

              <!-- Neither onAction or getPressed functions are called
                   when interacting with the checkbox on the form. -->
              <checkBox id="AddInEnabled"
                        label="Enable AddIn"
                        onAction="CheckBoxAction"
                        getPressed="CheckBoxPressed"/>

            </groupBox>
          </bottomItems>
        </group>
      </firstColumn>
    </tab>
  </backstage>
</customUI>

...这是 MyRibbon.cs

namespace MyAddIn {

    [ComVisible(true)]
    public class MyRibbon : Office.IRibbonExtensibility {

        // constructors, etc...

        public void ButtonAction(Office.IRibbonControl control) {
            System.Windows.Forms.MessageBox.Show(
                "ButtonAction: " + control.Id);
        }

        // Never gets called.
        public void CheckBoxAction(Office.IRibbonControl control) {
            System.Windows.Forms.MessageBox.Show(
                "CheckBoxAction: " + control.Id);
        }

        // Never gets called.
        public void CheckBoxPressed(Office.IRibbonControl control) {
            System.Windows.Forms.MessageBox.Show(
                "CheckBoxPressed: " + control.Id);
        }

    }
}

我的想法是在 MyRibbon 类中记录每个元素的状态,就像事件一样当用户与表单交互时触发。但是,由于有些东西(例如上面示例中的复选框)似乎不会触发任何可用的事件,因此我需要一些其他方法来从此类中查询后台。

因此,如果我有一个Apply按钮将表单状态保存在某处(代表加载项设置):我可以对单击该按钮做出反应,但如何才能获得复选框 那时的状态?

With Outlook 2010: if I have a checkbox defined in XML for the backstage to load, how can I query that element and get its status with C#? Here's an example of the backstage XML:

<?xml version="1.0" encoding="utf-8"?>
<customUI onLoad="Ribbon_Load"
          xmlns="http://schemas.microsoft.com/office/2009/07/customui">
  <backstage>
    <tab id="MyBackstageTab"
         getVisible="MyBackstageTab_GetVisible">
      <firstColumn>
        <group id="RegularGroup">
          <bottomItems>
            <groupBox id="GeneralGroupBox">

              <!-- This works fine; onAction is called every click. -->
              <button id="ApplyButton"
                      label="Apply"
                      onAction="ButtonAction"/>

              <!-- Neither onAction or getPressed functions are called
                   when interacting with the checkbox on the form. -->
              <checkBox id="AddInEnabled"
                        label="Enable AddIn"
                        onAction="CheckBoxAction"
                        getPressed="CheckBoxPressed"/>

            </groupBox>
          </bottomItems>
        </group>
      </firstColumn>
    </tab>
  </backstage>
</customUI>

...and here's the MyRibbon.cs:

namespace MyAddIn {

    [ComVisible(true)]
    public class MyRibbon : Office.IRibbonExtensibility {

        // constructors, etc...

        public void ButtonAction(Office.IRibbonControl control) {
            System.Windows.Forms.MessageBox.Show(
                "ButtonAction: " + control.Id);
        }

        // Never gets called.
        public void CheckBoxAction(Office.IRibbonControl control) {
            System.Windows.Forms.MessageBox.Show(
                "CheckBoxAction: " + control.Id);
        }

        // Never gets called.
        public void CheckBoxPressed(Office.IRibbonControl control) {
            System.Windows.Forms.MessageBox.Show(
                "CheckBoxPressed: " + control.Id);
        }

    }
}

My thinking is to record each elements' status, inside the MyRibbon class, as events are fired when the user interacts with the form. However, since some things (like the checkbox in my example above) don't seem to trigger any usable events, I need some other way to query the backstage from within this class.

So if I have an Apply button that will save the form state somewhere (representing AddIn settings): I can react to that button being clicked, but how can I also get the checkbox state at that point?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若有似无的小暗淡 2024-11-24 10:40:59

检查这个答案:如何访问后台Office 插件中的复选框值?

ps:我在写完我的问题后发现了您的问题 :)

Check this answer: How to access backstage checkbox value in an Office addin?

ps: I found your question after writing mine :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文