Home Banner image
Home

ProjectMIDI Menu & Toolbar Developer Information.

In this section I will describe how ProjectMIDI implements user configurable menus and toolbars.

Adding Items to ProjectMIDI's Menus and Toolbar

Menu and toolbar items can be added to ProjectMIDI's menus or toolbar using either ProjectMidiAttributes or by implementing specific ProjectMIDI interfaces.

Attributes

  1. ProjectMidiMenuEventAttribute
  2. ProjectMidiToolBarEventAttribute
  3. ProjectMidiContextMenuEventAttribute

Interfaces

Items can be added dynamically at ProjectMIDI startup by implementing one or more or the ProjectMIDI menu or toolbar interfaces.

  1. IHasMenus
  2. IHasContextMenuItems
  3. IHasToolbars

Implementing a Context Menu in a Custom Dialogs

By adding a context menu to your form, you allow the user to link to whatever actions they like. The context menu will be displayed whenever the user right-clicks on the form. The items displayed on the menu are specified by making connections from the event that we create for the context menu to any other action in any other ProjectMidi assembly! This is quite a powerful and useful feature.

As shown in the following code, implement a context menu using the following steps:

  1. Add a contextMenu control to the form.
  2. Create a context menu popup handler method.

    Select the contextMenu control, then double-click Popup property. This method is called prior to displaying the context menu. We'll add code to call each action connected to our context menu event passing them a reference to the contextMenu object.

  3. Add a new event with ProjectMidiEventAttribute

    private void SampleAssembly_Load(object sender, System.EventArgs e)
    {
    	contextMenu.Popup += new System.EventHandler(this.contextMenu_Popup);
    }
    
    [ProjectMidiMenuEventAttribute("ContextMenu",1,"Menu",ConnectionType.Normal,
    		"Displays connected action items on the Sample assmebly's context menu.")]
    public event ProjectMidiEventHandler ContextMenuEvent;
    
    // This event is fired before the icon menu is displayed
    private void contextMenu_Popup(object sender, System.EventArgs e)
    {
    	Console.WriteLine("Sample FireContextMenuEvent");
    	contextMenu.MenuItems.Clear();
    	MenuEventArgs e2 = new MenuEventArgs( contextMenu, "Sample" );
    	if(ContextMenuEvent != null) ContextMenuEvent( this, e2 );
    }