I am working with ArcMap and C#. In the bottom left hand corner, there is a menu where you can toggle between Data view and Layout View, a Pause button, and a refresh button. I have created an Add-in for ArcMap. I need to run some code when the Refresh button is clicked. Does anyone know the name of the event handler that controls the Refresh button? Or would anyone have some type of example where some code runs every time the Refresh button is clicked?
[GIS] Arcmap Refresh Button
arcmaparcobjectsc
Related Solutions
If you don't need any input or outputparameters, this sample should be possible to use to run a script in a custom command Leveraging ArcPy in a .NET application, C# example:
// Executes a shell command synchronously.
// Example of command parameter value is
// "python " + @"C:\scripts\geom_input.py".
//
public static void ExecuteCommand(object command)
{
try
{
// Create the ProcessStartInfo using "cmd" as the program to be run,
// and "/c " as the parameters.
// "/c" tells cmd that you want it to execute the command that follows,
// then exit.
System.Diagnostics.ProcessStartInfo procStartInfo = new
System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
// Now you create a process, assign its ProcessStartInfo, and start it.
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
// Get the output into a string.
string result = proc.StandardOutput.ReadToEnd();
// Display the command output.
Console.WriteLine(result);
}
catch (Exception objException)
{
Console.WriteLine(objException.Message);
// Log the exception and errors.
}
}
ESRI.ArcGIS.Controls.ToolbarControl class is for ArcGIS Engine Application and you shouldn't use it in ArcMap with ArcObject.
To Remove a command from a toolbar: You just need the name or UID of the command you want to remove from a toolbar. Suppose you want to delete fullExtent command from the Tools toolbar:
var fullExtent = asraArcMapEngine.getCommandItem("esriArcMapUI.FullExtentCommand");
fullExtent.Delete();
To Add a button to a Toolbar: 1- first you need to get a handle of the toolbar using this method:
public static ICommandBar GetToolbarByName(IApplication mapplication,String toolbarName)// Example: "esriArcMapUI.StandardToolBar"
{
ESRI.ArcGIS.Framework.ICommandBars commandBars = mapplication.Document.CommandBars;
ESRI.ArcGIS.esriSystem.UID barID = new ESRI.ArcGIS.esriSystem.UIDClass();
barID.Value = toolbarName;
ESRI.ArcGIS.Framework.ICommandItem commandItem = commandBars.Find(barID, false, false);
if (commandItem != null && commandItem.Type == ESRI.ArcGIS.Framework.esriCommandTypes.esriCmdTypeToolbar)
{
return (ESRI.ArcGIS.Framework.ICommandBar)commandItem;
}
else
return null;
}
Then use the method of ICommandBar to add your commands:
ICommandBar cmdBar = GetToolbarByName(application,"esriArcMapUI.StandardToolBar")
cmdBar.Add("UID_of_MyCustomCommand");
Best Answer
You probably just need to use the
IActiveView.Refresh
method to achieve what you're looking for. You can get the active view from theMxDocument.ActiveView
property. The help/snippets should lead you the rest of the way.