<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Button AddIn - programmatically changing the caption in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/button-addin-programmatically-changing-the-caption/m-p/120362#M3157</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;&lt;OL&gt;&lt;LI&gt;Can I change the caption in code?&lt;/LI&gt;&lt;LI&gt;Or does the new declarative framework not allow me to do this?&lt;/LI&gt;&lt;BR /&gt;&lt;/OL&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am also interested in knowing the answer to this question and i am also interested in changing the tooltip and message properties. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;My toolbar has a button that establish a connection to another system and i would like this button to read "Connect" when disconnected and "Disconnect" when connected and obviously, i would like to change their tooltips and message as well. Changing those two other properties result in exceptions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(COMException : "This method cannot be called on built in commands.")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Looking forward to an answer to this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 15 Nov 2011 11:48:24 GMT</pubDate>
    <dc:creator>CarlQuirion</dc:creator>
    <dc:date>2011-11-15T11:48:24Z</dc:date>
    <item>
      <title>Button AddIn - programmatically changing the caption</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/button-addin-programmatically-changing-the-caption/m-p/120361#M3156</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is it possible to change the caption of an AddIn button in code?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The button and it's containing toolbar are declared in the XML:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
&amp;nbsp; &amp;lt;AddIn language="CLR" library="DeleteThisArcMapAddinProject.dll" namespace="DeleteThisArcMapAddinProject"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ArcMap&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Commands&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Button id="DeleteThisArcMapAddinProject_Button1" class="Button1" message="Yada yada." caption="My Button" tip="tooltip." category="Add-In Controls" /&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Commands&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Extensions&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Extensions&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Toolbars&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Toolbar id="DeleteThisArcMapAddinProject_My_Toolbar" caption="My Toolbar" showInitially="true"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Items&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Button refID="DeleteThisArcMapAddinProject_Button1" /&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Items&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Toolbar&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Toolbars&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/ArcMap&amp;gt;
&amp;nbsp; &amp;lt;/AddIn&amp;gt;
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
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
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;OL&gt;&lt;LI&gt;Can I change the caption in code?&lt;/LI&gt;&lt;LI&gt;Or does the new declarative framework not allow me to do this?&lt;/LI&gt;&lt;BR /&gt;&lt;/OL&gt;&lt;SPAN&gt;TIA&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Oct 2011 17:30:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/button-addin-programmatically-changing-the-caption/m-p/120361#M3156</guid>
      <dc:creator>DirkVandervoort</dc:creator>
      <dc:date>2011-10-04T17:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: Button AddIn - programmatically changing the caption</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/button-addin-programmatically-changing-the-caption/m-p/120362#M3157</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;&lt;OL&gt;&lt;LI&gt;Can I change the caption in code?&lt;/LI&gt;&lt;LI&gt;Or does the new declarative framework not allow me to do this?&lt;/LI&gt;&lt;BR /&gt;&lt;/OL&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am also interested in knowing the answer to this question and i am also interested in changing the tooltip and message properties. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;My toolbar has a button that establish a connection to another system and i would like this button to read "Connect" when disconnected and "Disconnect" when connected and obviously, i would like to change their tooltips and message as well. Changing those two other properties result in exceptions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(COMException : "This method cannot be called on built in commands.")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Looking forward to an answer to this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Nov 2011 11:48:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/button-addin-programmatically-changing-the-caption/m-p/120362#M3157</guid>
      <dc:creator>CarlQuirion</dc:creator>
      <dc:date>2011-11-15T11:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Button AddIn - programmatically changing the caption</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/button-addin-programmatically-changing-the-caption/m-p/120363#M3158</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;There seems to be a disconnect between the UI button caption and the &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt; ICommandItem.Caption &lt;/SPAN&gt;&lt;SPAN&gt;property.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried some similar code in C#:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
private void ChangeButtonCaption()
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Get the collection of toolbars
&amp;nbsp;&amp;nbsp;&amp;nbsp; ICommandBars cmdBars = ArcMap.Application.Document.CommandBars;

&amp;nbsp;&amp;nbsp;&amp;nbsp; // Get the button
&amp;nbsp;&amp;nbsp;&amp;nbsp; UID uid = new UIDClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp; uid.Value = ThisAddIn.IDs.TestButton;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ICommandItem cmdItem = cmdBars.Find(uid, false, false);

&amp;nbsp;&amp;nbsp;&amp;nbsp; // skip out if no button
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (cmdItem == null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return;

&amp;nbsp;&amp;nbsp;&amp;nbsp; // report the current caption
&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Diagnostics.Debug.WriteLine("cmdItem.Caption: " + cmdItem.Caption);
&amp;nbsp;&amp;nbsp;&amp;nbsp; // change the caption
&amp;nbsp;&amp;nbsp;&amp;nbsp; cmdItem.Caption = "Test Button (clicked)";
&amp;nbsp;&amp;nbsp;&amp;nbsp; cmdItem.Refresh();
&amp;nbsp;&amp;nbsp;&amp;nbsp; // report the changed caption
&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Diagnostics.Debug.WriteLine("cmdItem.Caption: " + cmdItem.Caption);

&amp;nbsp;&amp;nbsp;&amp;nbsp; // Cannot set Tooltip: get error "This method cannot be called on built in commands"
&amp;nbsp;&amp;nbsp;&amp;nbsp; // This is mentioned in documentation for this property.
&amp;nbsp;&amp;nbsp;&amp;nbsp; //cmdItem.Tooltip = "Test tooltip. (clicked)";
}
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As the original poster reported, the UI caption never changes even though the caption property persists.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Further, after using ArcMap to change the UI caption (by opening the Customize dialog, then right-clicking on the button and editing the Name value), the new caption is reflected in the underlying &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;ICommandItem.Caption&lt;/SPAN&gt;&lt;SPAN&gt; property, but the UI caption still does not change when editing the property.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[added]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You can change the icon for the button. Inserting a line of code above with &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;cmdItem.FaceID = 1&lt;/SPAN&gt;&lt;SPAN&gt; works. See the &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/FaceID_Property/002300000079000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;ICommandItem.FaceId&lt;/A&gt;&lt;SPAN&gt; documentation for more info.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:00:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/button-addin-programmatically-changing-the-caption/m-p/120363#M3158</guid>
      <dc:creator>JeffreyHamblin</dc:creator>
      <dc:date>2021-12-11T07:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: Button AddIn - programmatically changing the caption</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/button-addin-programmatically-changing-the-caption/m-p/120364#M3159</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;According to another thread, the caption property bug will be fixed in 10.0 SP4 and 10.1:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/28201-Change-Caption-of-Base-Command"&gt;Change Caption of Base Command&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Nov 2011 17:10:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/button-addin-programmatically-changing-the-caption/m-p/120364#M3159</guid>
      <dc:creator>JeffreyHamblin</dc:creator>
      <dc:date>2011-11-22T17:10:27Z</dc:date>
    </item>
  </channel>
</rss>

