Change caption, icon, tooltip for Add-in button in program

2604
3
Jump to solution
06-26-2013 01:31 PM
Highlighted
New Contributor III
I'm trying to change the icon, caption and tooltip of an button in my custom toolbar. I'm using the add-in process inside Visual Studio.

Ideally I don't want an icon, just the text "English" or "Spanish" to appear on the toolbar depending on what the user clicks. If I can't have the text then an icon that can alternate between 2 different choices would be ok.

If I try to change the FaceID, ToolTip or Caption ArcMap crashes. I can get the contextHelpItem.Name property so I know I'm getting the correct button and toolbar.

ArcGIS 10.1, Visual Studio 2010, VB.net

         Dim documentBars As ICommandBars = m_Application.Document.CommandBars Dim barID As UID = New UIDClass barID.Value = "BGC_Engineering_Inc_BGCLayout_Tool_v4_BGC_Layout_Tool" '"{ebecdd6c-d4da-4523-b478-aab7f940b87e}" Dim barItem As ICommandItem = documentBars.Find(barID, False, False) If Not (barItem Is Nothing) Then ' AndAlso barItem.Type = ESRI.ArcGIS.Framework.esriCommandTypes.esriCmdTypeToolbar Then     Dim commandBar As ICommandBar = CType(barItem, ICommandBar)     Dim commandID As ESRI.ArcGIS.esriSystem.UID = New ESRI.ArcGIS.esriSystem.UIDClass     commandID.Value = "BGC_Engineering_Inc_BGCLayout_Tool_version_4_btn_Language"     Dim contextHelpItem As ICommandItem = commandBar.Find(commandID, False)     If Not contextHelpItem Is Nothing Then         ' get bitmap         'Dim newIcon As System.Drawing.Bitmap         If g_bEnglish = True Then            'newIcon = New System.Drawing.Bitmap(Me.GetType(), "Images/btn_Language_en.bmp")             'contextHelpItem.FaceID = ESRI.ArcGIS.ADF.COMSupport.OLE.GetIPictureDispFromBitmap(newIcon)             'contextHelpItem.Style = esriCommandStyles.esriCommandStyleTextOnly             'contextHelpItem.Caption = "English"             contextHelpItem.Tooltip = "Now English"         Else             'newIcon = New System.Drawing.Bitmap(Me.GetType(), "Images/btn_Language_es.bmp")             'contextHelpItem.FaceID = ESRI.ArcGIS.ADF.COMSupport.OLE.GetIPictureDispFromBitmap(newIcon)             'contextHelpItem.Style = esriCommandStyles.esriCommandStyleTextOnly             'contextHelpItem.Caption = "Spanish"             contextHelpItem.Tooltip = "Now Spanish"         End If     End If End If
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
MVP Frequent Contributor
Mathew,

For whats it worth I knocked together the following VBA code and was able to successfully change the caption on a toolbar button which is an ESRI Addin. This is what I used:

Public Sub ChangeText()     Dim pApp As IApplication     Set pApp = Application     Dim pCBs As ICommandBars     Set pCBs = pApp.Document.CommandBars     Dim pCI As ICommandItem     Set pCI = pCBs.Find("xxx_xxx_xxx")     Dim pCB As ICommandBar     Set pCB = pCI     Debug.Print pCB.Count ' Number of items of toolbar     Set pCI = pCB.Item(0)     Debug.Print pCI.BuiltIn ' Should returns true, which it does!     pCI.Style = esriCommandStyleIconAndText     pCI.Caption = "Spanish"     pCI.Refresh End Sub

View solution in original post

Reply
0 Kudos
3 Replies
Highlighted
MVP Frequent Contributor
Mathew,

For whats it worth I knocked together the following VBA code and was able to successfully change the caption on a toolbar button which is an ESRI Addin. This is what I used:

Public Sub ChangeText()     Dim pApp As IApplication     Set pApp = Application     Dim pCBs As ICommandBars     Set pCBs = pApp.Document.CommandBars     Dim pCI As ICommandItem     Set pCI = pCBs.Find("xxx_xxx_xxx")     Dim pCB As ICommandBar     Set pCB = pCI     Debug.Print pCB.Count ' Number of items of toolbar     Set pCI = pCB.Item(0)     Debug.Print pCI.BuiltIn ' Should returns true, which it does!     pCI.Style = esriCommandStyleIconAndText     pCI.Caption = "Spanish"     pCI.Refresh End Sub

View solution in original post

Reply
0 Kudos
Highlighted
MVP Honored Contributor
You should look up help on ESRI's website and msdn on the subject of Localization if you are trying to support a variety of local cultural settings, especially if your end users are likely to have their computers configured with different cultural environment settings in Windows.  Often many things change when moving between cultures (date and number formats being a common issue), which make you better off when you access the .Net cultural interfaces to manage the localization of your interfaces.

For example, check out this help and the additional links it has.
Reply
0 Kudos
Highlighted
New Contributor III
Thanks Duncan.
I forgot to add
contextHelpItem.Refresh

After that my changed caption became visible. I find it strange that you're allowed to change the Caption but not the ToolTip, but oh well.

I also found out how to change the icon for a different button on the toolbar. I have a button that toggles between a locked/unlocked state. For it work I had to have two bitmap images added as 'Embedded Resource', plus the initial image for the toolbar added separately (different filename) as an AddInContent

rfairhur24: Thanks for your suggestion. I will look into that further, but for now I'll leave the functionality the same. Usually it is done to change the borders of the map to Spanish text even though the ArcMap user is an English speaker. Some of our clients want their map borders in Spanish.
Reply
0 Kudos