Version: 10.2.1c and 10.2.1c SP3 |
ArcFM Engine Overview > Application Framework Overview > Commands in ArcFM Engine Applications > Button Command Code Sample |
This code sample illustrates a button command that refreshes the map which clicked by the user. This is the standard button that appears on a toolbar. The button used in the code sample in this section looks like this: . Implement button commands with your ArcFM Engine applications (e.g., ArcFM Viewer for ArcGIS Engine). Button commands must be added to a custom layout XML file before they will appear in the user interface.
![]() |
The default transparent color for bitmap icons is magenta (RGB - 255, 0, 255). |
This sample requires installation of the ArcFM Solution Software Developer Kit (SDK). You may need to change the existing installation in Add/Remove Programs to add Developer Resources.
While custom button commands may be created for Responder Explorer, this particular sample may not be used in Responder Explorer as there is no map display to be refreshed.
Product Availability: ArcFM Engine applications, ArcFM Viewer for ArcGIS Engine
References: Miner.Framework, Miner.Interop.Framework, Miner.Interop.System, Miner.Windows, Miner.Windows.ArcGIS
Set using directives for Miner.Windows.Command, Miner.Windows.ArcGIS, and Miner.Interop.
This command inherits from CommandButton.
Sets up the event handler for when the current map changes.
Set the base class properties and command properties in the constructor.
Override the onClick event. The sample onClick event refreshes the map.
Override the Enabled event. This sample calls IsEnabled. The code contained in IsEnabled could have been placed in the Enabled event instead.
Determines under what conditions the button is enabled. This could also be done in the Enabled event rather than here.
This is the code that executes when the event is fired.
C# Sample |
Copy Code
|
---|---|
using System; using System.Drawing; using System.Windows.Forms; using Esri.ArcGIS.Carto; using Esri.ArcGIS.esriSystem; using Esri.ArcGIS.Geodatabase; using Miner.Windows.Commands; //1 using Miner.Windows.ArcGIS; using Miner.Interop; namespace Miner.DeveloperSamples.Engine { public class DevMapRefreshCommand : ButtonCommand { #region Public Constructors/Destructors //2 public DevMapRefreshCommand() : base("DevMapRefreshCommand") { try { base.Caption = "Dev: Refresh View"; base.Image = new Bitmap(GetType().Assembly.GetManifestResourceStream(GetType().Namespace + ".Resources.MapRefresh.bmp")); //3 MainArcEngineApp.CurrentMapChanged +=new Miner.Windows.ArcGIS.MainArcEngineApp.CurrentMapChangedEventHandler(MainArcEngineApp_CurrentMapChanged); this.Category = "ArcFM Developer Samples"; //4 this.Caption = "Dev: Refresh Map"; this.CustomizerCaption = "Dev: Refresh Map"; this.CustomizerDescription = "Refreshes current map."; } catch (Exception exc) { MessageBox.Show("MapRefreshControl::MapRefreshControl" + exc.ToString()); return; } } #endregion Public Constructors/Destructors #region Overrides //5 protected override void OnClick(EventArgs args) { try { IActiveView pAV = MainArcEngineApp.FocusMap() as IActiveView; if (null != pAV) { pAV.Refresh(); } } catch (Exception exc) { MessageBox.Show("MapRefreshControl::Execute" + exc.ToString()); return; } } //6 public override bool Enabled { get { base.Enabled = IsEnabled(MainArcEngineApp.FocusMap()); return base.Enabled; } set { base.Enabled = value; } } #endregion Overrides #region Private Methods //7 private bool IsEnabled(IMap pMap) { try { bool bEnabled = false; if (null == pMap) return bEnabled; //now do the selecting UID pUID = new UIDClass(); if (null == pUID) return bEnabled; //IGeoFeatureLayer UID pUID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"; IEnumLayer pEnumLayers = null; try { pEnumLayers = pMap.get_Layers(pUID, true); } catch { return bEnabled; } if (null == pEnumLayers) return bEnabled; pEnumLayers.Reset(); IFeatureLayer pFLayer = null; ILayer pLayer = pEnumLayers.Next(); while (null != pLayer) { pFLayer = pLayer as IFeatureLayer; if (null != pFLayer) { bEnabled = true; break; } pLayer = pEnumLayers.Next(); } return bEnabled; } catch(Exception exc) { MessageBox.Show("MapRefreshControl::IsEnabled" + exc.ToString()); return false; } } //8 private void MainArcEngineApp_CurrentMapChanged(object sender, CurrentMapChangedEventArgs e) { bool checkEnabledStatus = Enabled; } #endregion Private Methods } } |
Return to Custom Commands and Controls