public override void Activate(ApplicationAddInSite addInSiteObject, bool firstTime)
{
base.Activate(addInSiteObject, firstTime);
//添加事件
Autodesk.Windows.ComponentManager.ItemInitialized +=new EventHandler<RibbonItemEventArgs>( ComponentManager_ItemInitialized);
}
void ComponentManager_ItemInitialized(object sender, RibbonItemEventArgs e)
{
//现在已初始化一个功能区项目,但是功能区控件可能尚不可用,因此先检测
if (Autodesk.Windows.ComponentManager.Ribbon != null)
{
foreach (Autodesk.Windows.RibbonTab Tab in Autodesk.Windows.ComponentManager.Ribbon.Tabs)
{
if (Tab.Id == "id_TabTools")
{
Tab.Activated += new EventHandler(Tab_Activated);
}
}
//移除事件
Autodesk.Windows.ComponentManager.ItemInitialized -=
new EventHandler<RibbonItemEventArgs>(ComponentManager_ItemInitialized);
}
}
void Tab_Activated(object sender, EventArgs e)
{
System.Windows.Forms.MessageBox.Show(
"Tab " + ComponentManager.Ribbon.ActiveTab.Id + " Activated!");
}