I am trying to create a custom button in arcmap that when pressed will edit a toolbars content. Doing things like adding or removing tools from a toolbar. An example would be to create a button that when pressed removes or toggles all the text/font editing tools from the draw toolbar.
I've been Looking at with IToolbarControl2 http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/IToolbarControl2_Interface/0016000003m7000000/ It seems to give access to various member functions that let me edit what I want. unfortunately I'm unsure of how to reference the specific toolbar that I want to edit.
I made some edits and currently the code runs and then hangs when i attempt to define axToolbarControl1.AddToolbarDef via:
axToolbarControl1.AddToolbarDef(uID, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
The current draft of the code is the following:
///Code to add or remove tools from a toolbar using System;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.IO;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.ArcMap;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS;
namespace RemoveAllTools2
{
public class RemoveAllTools2 : ESRI.ArcGIS.Desktop.AddIns.Button
{
IApplication m_application; //ArcMap application
IMxDocument m_mxDocument; //ArcMap document
public ESRI.ArcGIS.Controls.ToolbarControl axToolbarControl1;
public UID uID = new UIDClass();
public RemoveAllTools2()
{
MessageBox.Show("setup start");
m_application = ArcMap.Application;
MessageBox.Show("m_application set");
UID uID = new UIDClass();
uID.Value = "esriArcMapUI.DrawToolBar";
MessageBox.Show("UID set");
//code hangs here
axToolbarControl1.AddToolbarDef(uID, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
//code hangs here
MessageBox.Show("axtoolbar set");
}
protected override void OnClick()
{
MessageBox.Show("clicked");
IToolbarControl2 ttoolbarControl = axToolbarControl1.Object as IToolbarControl2;
MessageBox.Show("toolbarControl set");
uID.Value = "esriArcMapUI.FontNameControl";
int toolFindIndex = ttoolbarControl.Find(uID);
if (toolFindIndex!=-1)
{
ttoolbarControl.Remove(toolFindIndex);
MessageBox.Show("Tool remove run finished ");
}
else
{
MessageBox.Show("Tool not found");
}
MessageBox.Show("IF run finished ");
}
protected override void OnUpdate()
{
}
}
}