vandervoort

Button AddIn - programmatically changing the caption

Discussion created by vandervoort on Oct 4, 2011
Latest reply on Nov 22, 2011 by jeffhamblin
Is it possible to change the caption of an AddIn button in code?

The button and it's containing toolbar are declared in the XML:
  <AddIn language="CLR" library="DeleteThisArcMapAddinProject.dll" namespace="DeleteThisArcMapAddinProject">
    <ArcMap>
      <Commands>
        <Button id="DeleteThisArcMapAddinProject_Button1" class="Button1" message="Yada yada." caption="My Button" tip="tooltip." category="Add-In Controls" />
     </Commands>
      <Extensions>
      </Extensions>
      <Toolbars>
        <Toolbar id="DeleteThisArcMapAddinProject_My_Toolbar" caption="My Toolbar" showInitially="true">
          <Items>
            <Button refID="DeleteThisArcMapAddinProject_Button1" />
          </Items>
        </Toolbar>
      </Toolbars>
    </ArcMap>
  </AddIn>


As a dumb example, I want to change the cation of the button in response to the OnClick event of the button. BITD I could do it in COM ArcObjects by creating an instance of an ICommandItem. Here's a failed try:
Protected Overrides Sub OnClick()
 Dim uid As UID = New UIDClass()
 uid.Value = "DeleteThisArcMapAddinProject_Button1"
 Dim mx As MxDocument = DirectCast(My.ArcMap.Application.Document, MxDocument)
 Dim cmdBars As ICommandBars = mx.CommandBars
 Dim button As ICommandItem = cmdBars.Find(uid, False, False)
 System.Windows.Forms.MessageBox.Show(button.Caption)
 button.Caption = "My New Caption"
 My.ArcMap.Application.CurrentTool = Nothing
End Sub


What's funny (sic) about this is that the button.Caption value is "My New Caption" for subsequent OnClick events, even though the caption in the UI stays "My Button".

  1. Can I change the caption in code?
  2. Or does the new declarative framework not allow me to do this?

TIA

Outcomes