Click or drag to resize
Creating a custom command

A user interface extension project can implement custom commands in addition to event handlers and property pages. The commands will appear in the menu bar menus and context menus for the objects to which the extension is applied. The commands can also be grouped together on a sub-menu.

The following procedure includes steps for creating a command and a command group. Follow the steps as directed to create either or both.

To create a custom command with the UIExtensionComposer:

  1. Open an existing Visual Studio user interface extension project or create a new project as described in Creating a user interface extension.
  2. In Solution Explorer, open the UIExtensionComposer and open its properties.
  3. Click the ellipsis button Ellipsis button in the Commands property field in the Properties window. The Commands Collection Editor dialog lists the commands defined in the extension.
  4. Click the down arrow in the Add button and select Command to add the command to a parent menu (not a sub-menu). Select Command group to create a command group in which to add the command later in this procedure. A new command or command group is added to the Members list.
  5. If you created a command, set the Tag property to the name of the command as you want to refer to it in code and the Caption property to name of the command as you want it to appear to users. If you created a command group, set the Caption property to name of the parent menu item as you want it to appear to users. This property works the same as the Sub-menu name option of custom commands that are defined in Meridian Enterprise Configurator. Then click OK.
  6. If you created a command group, again click the ellipsis button Ellipsis button in the Commands property field in the Properties window. The Commands Collection Editor dialog lists the commands defined in the command group. Continue from step 4 to create a command or a separator. If you created a command, click the Events buttonin the UIExtensionComposer toolbar. The event names appear.
  7. Double-click the CommandExecute event in the BC Meridian General group.
  8. Visual Basic .NET creates an empty event handler method and adds it to your code, similar to the following example.
Private Sub UIExtensionComposer_CommandExecute(ByVal sender As Object, _
            ByVal e As CommandItemEventArgs) Handles MyBase.CommandExecute
  ' TODO: Add your execute command event handling code here.
End Sub

This procedure will handle the Execute event for all commands defined in the extension. If you have more than one command in the same project, then you can use Tag property to distinguish between the commands, similar to the following example.

Private Sub UIExtensionComposer_CommandExecute(ByVal sender As Object, _
            ByVal e As CommandItemEventArgs) Handles MyBase.CommandExecute
  Dim command As BCExtensionCommand = e.Command
  ' Use Tag property to distinguish between commands.
  Select Case e.Command.Tag.ToString()
    Case "MyCommand"
    ' Add handling code here for the command.
  End Select
End Sub

You can also add a command programmatically:

  1. Define an event handler method whose signature matches the delegate signature for the CommandExecute event, similar to the following example.
  2. Open the UIExtensionComposer in the code editor, find the code of the method’s constructor, and add a new command to the Commands collection, similar to the following example.
Private Sub CustomCommandHandler(ByVal sender As Object, ByVal e As CommandEventArgs)
  ' TODO: Add your execute command event handling code here.
End Sub
Public Class UIExtensionComposer
Public Sub New()
    ' Initialization code goes here...
    ' Add custom command programmatically.
    Dim command As BCExtensionCommand = New BCExtensionCommand( _
      "Custom Command", AddressOf CustomCommandHandler)
    Commands.Add(command)
End Sub

  ' Extension code goes here... 
End Class

The custom command can be shown in the Tools menu of Meridian Enteprise PowerUser. To do so, apply the extension to the Environment class either with Meridian Enteprise Configurator or programmatically in the ExtensionRegister event handler similar to the following example:

Private Sub UIExtensionComposer_ExtensionRegister(ByVal sender As Object, _
            ByVal e As ExtensionRegisterEventArgs) Handles MyBase.ExtensionRegister
  ' This assigns your extension the environment class    
  ' You only need to register this extension in your vault to add    
  ' the commands to the Tools menu of the PowerUser
  AddExtensionToClass(e.Environment, e.ExtensionRef, ObjectKind.AMEDM_AMENVIRONMENT)
End Sub
See Also