Skip to main content
deleted 144 characters in body; edited tags
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

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.

Any help or comments would be greatly appreciated.

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.

Any help or comments would be greatly appreciated.

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.

Tweeted twitter.com/#!/StackGIS/status/554842604953952256

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.

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.

///Code to add or remove tools from a toolbar using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Desktop;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.SystemUI;

namespace RemoveAllTools
{
public class RemoveAllTools : ESRI.ArcGIS.Desktop.AddIns.Button
{
    IApplication m_application;        //ArcMap application
    IMxDocument m_mxDocument;          //ArcMap document
    public ESRI.ArcGIS.Controls.AxToolbarControl axToolbarControl1;   
    
    public RemoveAllTools()
    {
        MessageBox.Show("setup start");
        m_application = ArcMap.Application;
        MessageBox.Show("m_application set");
    }


    protected override void OnClick()
    {
        MessageBox.Show("clicked");
        IToolbarControl2 ttoolbarControl = axToolbarControl1.Object as IToolbarControl2; 
        MessageBox.Show("axToolbarControll set");
        MessageBox.Show("addtoolbar def set");
        ttoolbarControl.RemoveAll();
        MessageBox.Show("RemoveAll 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. Any help or comments would be greatly appreciated.

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.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()
    {

    }
} 

}

Any help or comments would be greatly appreciated.

Removed request for code from title
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Code to add Add and remove tools from a ArcMap 10.2 toolbar via a C# Button and ArcObjects?

Source Link
Loading