繁体   English   中英

如何禁用Excel内置RibbonButton?

[英]How to disable Excel built-in RibbonButton?

是否可以将一个内置在RibbonButton中的excel 2010设置为从excel VSTO加载项启用= false?

我尝试了以下方法:

CommandBarControls controlls=Globals.ThisAddIn.Application.CommandBars.FindControls(MsoControlType.msoControlButton, 7374, null, false);
/// 7374 is the office control id of the control I want to access

foreach (CommandBarControl control in controlls)
{
    control.Enabled = false;
}

但这似乎只适用于右键单击上下文菜单。 而不是功能区按钮。

除非使用startFromScratch功能区UI属性,否则只能禁用选项卡而不是控件。 请参阅MSDN以供参考

另请参阅Ribbon XML FAQ以获取有关Excel功能区操作的良好资源。

不确定这是否对您有所帮助,但对于自定义功能区,您可以使用功能区XML实现getEnabled回调。

在XML中:

<button id="btnMyButton" ... getEnabled="OnMyButton_GetEnabled" onAction="..."/>

在代码隐藏中:

public bool OnMyButton_GetEnabled(Office.IRibbonControl rControl)
{
  // return true or false to enable or disable 
}

如果需要强制调用这些回调(例如,由于某些其他事件而设置了启用/禁用状态变量IRibbonUI.Invalidate()则需要调用IRibbonUI.Invalidate()方法。

顺便说一句,Ribbon Designer界面(在VS 2010上)似乎没有提供实现getEnabled回调的能力。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM