OK I updated the draft with some of the suggestions but am still having some issues.
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);
///Code to add or remove tools from a toolbar using System;
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;Windows.Forms;
using System.Windows.Forms;IO;
using ESRI.ArcGIS.ArcMapUI;Framework;
using ESRI.ArcGIS.Desktop;ArcMap;
using ESRI.ArcGIS.Framework;ArcMapUI;
using ESRI.ArcGIS.esriSystem;Controls;
using ESRI.ArcGIS.Controls;esriSystem;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS;
namespace RemoveAllToolsRemoveAllTools2
{
public class RemoveAllToolsRemoveAllTools2 : ESRI.ArcGIS.Desktop.AddIns.Button
{
IApplication m_application; //ArcMap application
IMxDocument m_mxDocument; //ArcMap document
public ESRI.ArcGIS.Controls.AxToolbarControlToolbarControl axToolbarControl1;
public UID uID = new UIDClass();
public RemoveAllToolsRemoveAllTools2()
{
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("axToolbarControll"toolbarControl set");
MessageBoxuID.Show("addtoolbarValue def= set""esriArcMapUI.FontNameControl";
int toolFindIndex = ttoolbarControl.Find(uID);
if (toolFindIndex!=-1)
{
ttoolbarControl.RemoveAllRemove(toolFindIndex);
MessageBox.Show("RemoveAll"Tool remove run finished ");
}
else
{
MessageBox.Show("Tool not found");
}
MessageBox.Show("IF run finished ");
}
protected override void OnUpdate()
{
}
}
}
My current crash location in the code is bolded. The reason for the crash seem to be due to me not properly initializing axToolbarControl1.
It seems that what I need is to find is a way to reference my IToolbarControl2 variable to the specific toolbar that I want to edit the properties of.
AnyAny help or comments would be greatly appreciated.