ICommandItem.Refresh does not reread ICommand Caption (version 10)

107
6
08-15-2011 08:15 AM
New Contributor
I am migrating an ArcMap 9.3 extension to version 10.  After a particular user action I am changing the caption value for an ICommand instance.  In previous versions of ArcObjects this change would be shown to the user immediately.  In version 10 the change to the command's caption does not result in any repaint of the gui.  To fix this I am calling the Refresh method of the ICommandItem object which holds the ICommand.  The API states that calling Refresh will cause "the command item to be redrawn on the CommandBar in order to correctly display any new property changes."
Is there something I'm missing?
Reply
0 Kudos
6 Replies
New Contributor
After changing the ICommand's caption, I was able to get ArcGIS to reread the new Caption value by calling the Reset method on ICommandItem.  But for some reason this still does not change the visible text on the button.
Does anyone have any idea how to get this to work?  I'm not sure why this is so hard to do.
Reply
0 Kudos
New Contributor
I am Bumping this thread since I have tried to call Refresh and Reset on the ICommandItem that contains the ICommand whose caption has been changed.  Neither method will update the gui to the newly set value of the caption (i.e. a call to ICommand.Caption returns a different value). 

Has anyone had any experience with changing the caption of a command dynamically based on user actions on other commands (e.g. mouse click)?

Thanks,
Robin
Reply
0 Kudos
New Contributor III
Maybe is it not meant to be changed it has only get property.
http://resources.esri.com/help/9.3/ArcGISDesktop/ArcObjects/esrisystemui/ICommand_Caption.htm

But i have solution for you.
Create window form ToolbarControls and create on it standard Label control

[System.Runtime.InteropServices.ComVisible(true)]
public partial class ToolbarControls : Form
{

}

Create static class that will hold {get; set;} public static reference to the Form ToolbarControls with label
public static class HwndHolder
{[INDENT]     public static ToolbarControls _ToolbarControls = null;
    public static Forms.ToolbarControls ToolbarControls
            {[INDENT]                     get{        return _ToolbarControls;        }
        set{        _ToolbarControls = value;       }
[/INDENT]}
[/INDENT]}

create Command with the IToolControl sou you can use hwnd attribute
public class cmd_Label : IToolControl, ICommand
{[INDENT]     public int hWnd
    {[INDENT]         get{      return ToolbarControls.Label_Control.Handle.ToInt32();                        }
[/INDENT]}
[/INDENT]}

Add control to the toolbar in the IToolBarDef.GetItemInfo with index and item GUID
If GUID not expicit defined it will be Namespace.ClassName if in root of solution and if in folder then Namespace.FolderInSolution.ClassName.

I tried Label.onClick and it works by changing text each time i click

Happy coding
Reply
0 Kudos
New Contributor III
I just saw that I misses one key point here that is I wrote and tested it in v.9.3.1 and you are trying that in v.10.
Sorry but at the moment I'm unable to run the test at ArcGis 10 to prove does it work.
Reply
0 Kudos
New Contributor
Thanks you very much Dubravko.  I was able to get this working from the notes you provided. 
I ended up going with two classes since I did not need a complete form, only a tool I can add to my BaseToolbar:

//first class is a Label class containing all of the event handlers I used to have in my ICommand class

//second class is:
public sealed class ControlAdapter : BaseTool, IToolControl{
       private static Label myLabel;
      
       public override void OnCreate(object hook){ //init label here }
       public int hWnd { get { return myLabel.Handle.ToInt32(); } }

       //all of the events I wanted to handle which are passed to myLabel
      ...
}

Basically all I needed was an adapter class to have ArcObjects use a simple windows control.  Thank you very much for your help!
Reply
0 Kudos
New Contributor III
Would you be able to post your code as an example of how to do this?

Thanks,
Reply
0 Kudos