Addin Button - Icon AND text (Image and Caption)  how?

7658
13
04-07-2011 07:50 AM
MichaelRobb
Occasional Contributor III
Hi everyone,

Simple but frustrating problem:
Prior to arcAddinx, there was no problem choosing to have Image / Text or Both for any button when a toolbar was loaded using the following code below triggered off the ENABLED using ESRICommandStyles.  (IToolbarDef)

        Public Sub SetAsIconAndText()

                ' Make sure button is showing Icon And Text
                Dim pUID As New UID
                pUID.Value = "{F53B91E1-C520-41a7-941C-686AA071D1A2}"  ' Toolbar GUID

            Dim pCommandBar As ESRI.ArcGIS.Framework.ICommandBar
            pCommandBar = m_application.Document.CommandBars.Find(pUID, True, False)

            Dim i As Integer
            If Not pCommandBar Is Nothing Then
                For i = 0 To pCommandBar.Count - 1
                    If pCommandBar.Item(i).Name = "FocusCorp_FocusEllipse" Then ' use the Property NAME of the button
                        pCommandBar.Item(i).Style = esriCommandStyles.esriCommandStyleIconAndText
                        Exit For
                    End If
                Next
            End If


        End Sub


I am aware that a user can AFTER the fact customize, but why would ESRI have left this functionality out with Addin XML?

Is there anyone that has found the means to control what each button displays on created toolbars when using Addins as far as Image and Caption?

Suggestions appreciated,

vb.net

Thanks
0 Kudos
13 Replies
SoniaScialanca
New Contributor
Hi Mike,
I'm just trying in these days to port some custom functionalities from 9.3.1 to 10, using add ins.
To change a command style I'm using your same method with only one difference: the UID.
The code is C#:

UIDClass p_UID = new UIDClass();
p_UID.Value = ThisAddIn.IDs.<ButtonID>;
ICommandItem p_CommandItemLogin = ((IDocument)ArcMap.Document).CommandBars.Find(p_UID, false, true) as ICommandItem;
p_CommandItemLogin.Style = ESRI.ArcGIS.SystemUI.esriCommandStyles.esriCommandStyleIconAndText;
p_CommandItemLogin.Refresh();


The ButtonID is the "id" value in the tag "Button", in the config.esriaddinx, but there's no need to write it, you should find it as a static value from ThisAddIn.IDs.

Instead, I'm looking for a method to change the image of a button after some actions.
Something like the old:

base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);


Can you help me for this problem?
Thank you.

Sonia
0 Kudos
DavidWilcox
New Contributor II
Has anyone found a way to dynamically modify the addin button icon or text?

Thanks!

- Dave
0 Kudos
SoniaScialanca
New Contributor
0 Kudos
MichaelRobb
Occasional Contributor III
I found this:

http://gis.stackexchange.com/questions/1297/can-you-programmatically-change-the-button-image-for-a-e...

and it works for me! 😄


perhaps I should have clarified...
I am aware of Caption and all XML variables within the esriaddinx config file... Caption gives the text under the Customize Mode >Commands window, as it should.

The question was... how does one, when creating a toolbar with buttons, have an IMAGE and TEXT (text for the image) appear on the toolbar ** using Addins?  (Have no problems using dll old method with Command Style
(I only found a way to use drop downs and have image AND text together, but not simply a button on a toolbar...

Once the button is on the bar, the user then MUST go to Customize >> Customize mode and right click on the image and click from DEFAULT to 'Image and Text' to have the button and Text both visible.

The question was, is there a way to have Button AND text show up on a toolbar as seen in the pic here, I have to manually change to have BOTH icon and text show on the toolbar as seen below for PrecisionXY example.
0 Kudos
JeffreyHamblin
New Contributor III
Hi Mike,

I believe you can achieve this in an extension as an addition to the way we handled the top menu in your other post: Modify-(add)-to-MAIN-Toolbar-with-Addinx-files.

Just call this little method in the same event handlers (sorry for the C#, but I'm sure you can convert it to vb.net easily):
private void SetButtonStyle()
{
    ICommandBars commandBars = ArcMap.Application.Document.CommandBars;
    ICommandItem commandItem = commandBars.Find(ThisAddIn.IDs.YourButtonClassNameHere, true, false);

    if (commandItem != null)
    {
        commandItem.Style = esriCommandStyles.esriCommandStyleIconAndText;
    }
}


Again, not thoroughly tested, but works for me on a quick test.

The code you included in your initial post was a big help.
0 Kudos
MichaelRobb
Occasional Contributor III
This specifically was for a toolbar / buttons... so create an extention just to control the command styles? seems silly... let me see if that works...
you cant access THISaddin and look for that button as its not contained in the Extension addin.  its in a separate addin.

How would one trigger on 'creation' when the Addin is added, its not possible is it?


The code below works, but never found a way to have it work on loading the toolbar.
OnClick - well, thats too late
OnUpdate ?
Sub Finalize?

    Public Sub SetAsIconAndText()

        ' Make sure button is showing Icon And Text
     '   Dim pUID As New UID  'not needed
     '   pUID.Value = My.ThisAddIn.AddInID ' ' Toolbar GUID ' not needed

        Dim pCommandItem As ESRI.ArcGIS.Framework.ICommandItem
        pCommandItem = My.ArcMap.Application.Document.CommandBars.Find(My.ThisAddIn.IDs.PrecisionXYButton, true, false)

        pCommandItem.Style = ESRI.ArcGIS.SystemUI.esriCommandStyles.esriCommandStyleIconAndText



    End Sub


jeff... you were a ton help in getting me going with creating Root Menu drop down items and pointing to other buttons/commands btw...
0 Kudos
MichaelRobb
Occasional Contributor III
Just to summarize...

This does work, if a) you build a toolbar with commands (buttons)  ...
you must then build an EXTENSION to use the Events.NewDocument and Events.OpenDocument.

Currently I do not know of a way of adjusting the Command style through the Toolbar/buttons added in a specific Addin file. - the ORIGINAL Question.

then find the UID value for that specific command Item...
like so...

    Public Sub SetAsIconAndText()

        ' Make sure button is showing Icon And Text
        Dim pUID As New UID
        pUID.Value = "{6298A204-AD3A-9573-D5E7-E8952250BA36}"  ' Toolbar GUID"

        Dim pCommandItem As ESRI.ArcGIS.Framework.ICommandItem
        pCommandItem = My.ArcMap.Application.Document.CommandBars.Find(pUID, True, False)

        pCommandItem.Style = ESRI.ArcGIS.SystemUI.esriCommandStyles.esriCommandStyleTextOnly



    End Sub
0 Kudos
DubravkoAntonic
New Contributor III
I'm not sure this can be done because...
AddIns are not loaded at Application StartUp , Delay loading, but on Button click.
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Advanced_add_in_concept...

ArcMap in general prefers to make UI changes after IApplicationStatus.Initialized which you can not trap because your AddIn is not running.

I didn't tested but it looks to me ArcMap is saving AddIn settings in Normal.mxt. And if I'm right then it can't be done without any kind of extension that is detecting and modifying the ArcMap.

Regards Dubravko Antoni�?
0 Kudos
SoniaScialanca
New Contributor

The code below works, but never found a way to have it work on loading the toolbar.
OnClick - well, thats too late
OnUpdate ?
Sub Finalize?

I'm not sure if it's completely right, but I've used this code inside the OnUpdate method and it works for me, I've no need to change the style manually.
Note that the OnUpdate method is called many times during the start up of ArcMap, but the first few times, even if the object (button) exists, it is not really initialized, due to the delay mentioned by dubravko.antonic:

AddIns are not loaded at Application StartUp , Delay loading...

So, only after the button it's really loaded the code works and for this reason I decided to use it inside OnUpdate method: despite this delay I can see the style changed even if I don't click on the button. (in config.esriaddinx I also set the OnDemand on false).
0 Kudos