![](/img/trans.png)
[英]How to disable Excel built-in RibbonButton in Ribbon (Visual Designer)?
[英]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.