Access Add-in Button.Caption in Code

2020
2
Jump to solution
06-12-2014 01:14 AM
FridjofSchmidt
Occasional Contributor
Dear all,

Can anybody tell me how to read the Caption, Message and Tooltip properties of an ArcMap Add-in Button programmatically? The properties are defined in the Config.esriaddinx file and are shown correctly in ArcMap. However, when I try to query them, say, in the Button's OnClick method, I only get an empty string:

    public class DummyButton : Button     {         protected override void OnClick()         {             MessageBox.Show(string.Format("Button '{0}' was clicked!", this.Caption));         }     }


On the other hand, it is possible to change the properties Message and Tooltip programmatically, and the update is reflected both in ArcMap and in code. The Caption can be changed too and will be available in code, although in ArcMap the button's caption won't be updated. But how to get the values that are defined in the config file? Btw, I'm using ArcGIS for Desktop 10.2.

Thanks for any hints,
Fridjof
0 Kudos
1 Solution

Accepted Solutions
ErinBrimhall
Occasional Contributor II
Hello Fridjof,

In order to access and modify the "true" Caption, Tooltip, etc. of the button, you need to work with the ICommand object that is registered as part of your Add-In (as defined in its Config.esriaddinx).

You can accomplish this by using the "ThisAddIn" class (an auto-generated helper class), and the "CommandBars" property of the current IDocument object.

See the code below:


ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass(); uid.Value = ThisAddIn.IDs.MyCustomButtom;  ESRI.ArcGIS.Framework.ICommandItem commandItem = ArcMap.Application.Document.CommandBars.Find(uid); commandItem.Caption = "New Caption"; commandItem.Message = "New Message"; commandItem.Tooltip = "New Tooltip";



Changing the properties on the ICommand will update the button in ArcMap.

Hope this helps!

View solution in original post

0 Kudos
2 Replies
ErinBrimhall
Occasional Contributor II
Hello Fridjof,

In order to access and modify the "true" Caption, Tooltip, etc. of the button, you need to work with the ICommand object that is registered as part of your Add-In (as defined in its Config.esriaddinx).

You can accomplish this by using the "ThisAddIn" class (an auto-generated helper class), and the "CommandBars" property of the current IDocument object.

See the code below:


ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass(); uid.Value = ThisAddIn.IDs.MyCustomButtom;  ESRI.ArcGIS.Framework.ICommandItem commandItem = ArcMap.Application.Document.CommandBars.Find(uid); commandItem.Caption = "New Caption"; commandItem.Message = "New Message"; commandItem.Tooltip = "New Tooltip";



Changing the properties on the ICommand will update the button in ArcMap.

Hope this helps!
0 Kudos
FridjofSchmidt
Occasional Contributor
Hi Erin,

Thanks, that's what I was looking for!
0 Kudos