By ICommandItem.Execute you'll have focus on BaseCommand item. It is a bit unusual way to have focus on ICommand object that is meant to be executed without any user interaction.
Maybe it is a better way for you to create your own custom tool that implements functions of some BaseCommand item, that way you can make focus on it.
What is Use Case that you are trying to implement?
some general utility class public static ICommandItem FindTool(string toolGUID) { ICommandItem item = null; try { UID pUID = new UIDClass(); pUID.Value = toolGUID; item = Extension.Application.Document.CommandBars.Find(pUID, false, false); } catch { } return item; }
//member private ICommandItem m_currentTool = null; //method // use form activated method for checking and setting current tool private void ToolForm_Activated(object sender, EventArgs e) { if (Extension.Application.CurrentTool == null || Extension.Application.CurrentTool.Caption != currentTool.Caption) { Extension.UIState = Extension.UIStates.SomeState; Extension.Application.CurrentTool = currentTool; } }
A command cannot have focus unless it is also a tool. Commands are one click kind of deals, they don't have any focus. When you click on your command and the form pops up, the current tool is still the previous one. Now what you do when the form is open is up to you. If the users are not to have any interaction with arcmap, make the form modal, this will prevent focus from shifting from the form back to the map. If that is not your goal, you can also set the current tool to the select elements tool, it is a de facto default tool.
Don't be afraid to implement new things, tool is not that complicated at all. Use ArcGisWizard in VS for creating ArcMap Tool. Use OnClick for opening the form. Test how and when this event is triggered.
For this UseCase you can when form receives a focus checks, Form_Activated event, if Application.CurrentTool is your tool. If is not, then Find tool by GUID and set it as your current tool.
here are some hintssome general utility class public static ICommandItem FindTool(string toolGUID) { ICommandItem item = null; try { UID pUID = new UIDClass(); pUID.Value = toolGUID; item = Extension.Application.Document.CommandBars.Find(pUID, false, false); } catch { } return item; }
tool GUID is string {...} or you can do it by ProgID which is namspace.className
form class//member private ICommandItem m_currentTool = null; //method // use form activated method for checking and setting current tool private void ToolForm_Activated(object sender, EventArgs e) { if (Extension.Application.CurrentTool == null || Extension.Application.CurrentTool.Caption != currentTool.Caption) { Extension.UIState = Extension.UIStates.SomeState; Extension.Application.CurrentTool = currentTool; } }