在 Word 2007 插件中启用/禁用功能区按钮

发布于 2024-11-03 09:00:57 字数 175 浏览 1 评论 0原文

目前我正在开发一个 Word Addin,其中我已动态地将控件添加到功能区。现在,我需要捕获动态按钮“btnSubmit”,并根据我需要启用/禁用该按钮的条件。

当文档第一次打开时,它应该被启用,一旦单击按钮,它应该被禁用。

这应该在布尔条件下完成。任何帮助将不胜感激。

谢谢, 普拉萨德

Currently i am working on a word Addin, where i have added controls to the ribbon dynamically. Now, I need to catch the dynamic button "btnSubmit" and based on the condition i need to enable/disable the button.

when the document is opened for the first time it should be enabled and Once the Button is clicked it should be disabled.

This should be done on a boolean condition. Any help would be greatly appreciated.

thanks,
KSR Prasad

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

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

发布评论

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

评论(3

无尽的现实 2024-11-10 09:00:57

可以通过 RibbonXML 使用 getEnabled 事件来实现。

功能区 XML:

<button id="button1" onAction="button1_Click" getEnabled="button1_EnabledChanged" />

代码:

public void button1_Click(Office.IRibbonControl control)
{
    if (control.Id == "button1")
    {
        // your code
        clicked = true; // a boolean variable
    }
}

public bool button1_EnabledChanged(Office.IRibbonControl control)
{
    if (control.Id == "button1")
        return !clicked;
}

It is possible through RibbonXML using the getEnabled event.

Ribbon XML:

<button id="button1" onAction="button1_Click" getEnabled="button1_EnabledChanged" />

Code:

public void button1_Click(Office.IRibbonControl control)
{
    if (control.Id == "button1")
    {
        // your code
        clicked = true; // a boolean variable
    }
}

public bool button1_EnabledChanged(Office.IRibbonControl control)
{
    if (control.Id == "button1")
        return !clicked;
}
℉服软 2024-11-10 09:00:57

如果您已经创建了按钮,只需创建一个区域范围的WIEVENTS变量来保存它,分配它,然后对单击事件做出反应以禁用该按钮(按钮对象具有启用属性)。

Private WithEvents _MyButton As Ribbon.RibbonButton
....
Set _MyButton = {the just created button}

然后处理点击事件

If you've already created the button, just create a regional scope WITHEVENTS variable to hold it in, assign it, then react to the click event to disable the button (the button object has an enabled property).

Private WithEvents _MyButton As Ribbon.RibbonButton
....
Set _MyButton = {the just created button}

then handle the click event

我不会写诗 2024-11-10 09:00:57

我对此类问题的偏好是使用 RibbonXml 而不是设计器。

一个非常简单的选择是拥有一个字典,然后您可以将其存储在功能区回调类中。如果您想要更好的选择,VSTO Contrib (http://vstocontrib.codeplex.com/) 允许您轻松地为每个文档创建一个“视图模型”,然后您只需将启用的按钮绑定到视图模型上的属性即可。

有关功能区 xml 的更多信息: http://jake.ginnivan.net/vsto-ribbon -设计师深入
有关 vsto contrib 及其如何帮助您的更多信息:http://jake.ginnivan.net /vsto-contrib/ribbon-factory

干杯,
杰克

My preference for this type of issue is to use RibbonXml rather than the designer.

A really simple option would be have a Dictionary which you can then store in the ribbon callback class. If you wanted a nicer option, VSTO Contrib (http://vstocontrib.codeplex.com/) allows you to create a 'viewmodel' per document quite easily, then you simply can bind the button enabled to a property on the viewmodel.

More info on ribbon xml: http://jake.ginnivan.net/vsto-ribbon-designer-in-depth
More info on vsto contrib and how it can help you: http://jake.ginnivan.net/vsto-contrib/ribbon-factory

Cheers,
Jake

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