Responder Developer Guide
Button Command Code Sample

Resource Center Home

Product Availability: Responder

This section discusses how to create a button command in Responder Explorer or Archive Explorer and display that command in a particular category on the Customize menu. The code sample below demonstrates how you may create a button command. The Add Responder Command to the User Interface page discusses how to include this command on a toolbar in your Responder Explorer or Archive Explorer user interface.

The sample on this page adds the above command

The default transparent color for bitmap icons is teal (RGB - 0, 128, 128).

Create the Command

  1. Context menu commands should derive from Miner.Windows.Commands.ButtonCommand.
  2. Create a unique key for the command and expose it through a public constant called _CmdKey on the class.
  3. Specify a default constructor that initializes the base class with this key and other optional data.
  4. Assign your button command to a specific category in the customize menu. If the name provided doesn't match an existing category name, the new category will be created.

  1. Override the OnClickevent. This is where the code to be executed will be fired when the command is selected in the context menu.
  2. To filter when the command is enabled, listen to the Miner.Data.Decoration.DataSelectionMonitor.DataSelectionChanged event (for notification as to when the selected row(s) have changed) and conditionally set the Enable property of the command.

 

Button Command
Copy Code
using System;
using System.Windows.Forms;
using Miner.Data.Decoration;
using Miner.Responder.Shared;
using Miner.Windows.Commands;
using Miner.Resource;
using System.Reflection;
 
 
namespace CommandTest
{
//1
    public class CommandButtonTest : ButtonCommand
    {
 
//2
        public const string _Cmdkey = "TestCmd";
 
//3
        public CommandButtonTest() : base(_Cmdkey, "Test Command", "This is a sample button command.", Imaging.LoadBitmap(Assembly.GetAssembly(typeof(CommandButtonTest)),"testcmd"))
        {
//4
            Category = "New Category";
            DataSelectionMonitor.DataSelectionChanged += DataSelectionMonitor_DataSelectionChanged;
            ShowInCustomizer = true;
            Description = "I am just testing how to add a new command button for a context menu.";
        }
 
//5
        protected override void OnClick(EventArgs args)
        {
            // The action performed when the command is actived.
            MessageBox.Show(null, "Test command was activated.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
 
        /// <summary>
        /// Handles the DataSelectionChanged event of the DataSelectionMonitor control.
        /// </summary>
//6
        private void DataSelectionMonitor_DataSelectionChanged(object sender, DataSelectionEventArgs e)
        {
            // Make this command enabled when the data is associated with the incidents table.
            Enabled = e.TableName.Equals(RxDb.TableRepresents.Incidents.TableName, StringComparison.InvariantCultureIgnoreCase);
        }
 
    }
}

 

 

 

 


Send Comment to ArcFMdocumentation@schneider-electric.com