|
Tutorial 1 - Menu Item and event handler. |
Top Previous Next |
|
In this first tutorial, we're going to see how to integrate a new menu item in BLIde. We'll create a menu option inside the Add-ons menu of BLIde. This new menu item will have the text "Hello world" and will display a Hello world message window when pressed (or when the associated shortcut is pressed).
First of all, we're going to create a copy of our empty plugin template, and go directly to the PluginModule.vb file:
First of all, as our plugin is not intended to be a Hello World message, we'll delete the IO.Msg sentece, this way:
Then, we'll see how to create a new Menu Item on BLIde.
Menu items, on BLIde are object of the kind: BLIde.SDK.BLIdeForms.BLIdeMenuItem, so first of all, we add a menu item declaration.
This has been easy. However, while we're declaring a MenuItem variable, we need to assign it a value. Keep in mind that MenuItem objects have to be parented to a MenuBar item, or to another MenuItem object, so in order to really create and instantiate a MenuItem variable, we have to specify where to place the item! It can't be created in the middle of nowhere!
To do so, the BLIde SDK provides a shared class called BLIde.SDK.Api that contains all the MenuBarItems in the default BLIde Menu, so we can do:
MenuItem = New BLIdeForms.BLIdeMenuItem(Api.AddOnsBarItem)
In this case, the parameter Api.AddOnsBarItem is telling BLIde that the BLIdeMenuItem object that is being create, is parented to the AddOns menu item.
By now we should have this plugin source code:
If we run the Plug-in (F5), BLIde will be started. Once BLIde is started, if we go to the Add Ons menu, we'll see this:
We can see we've added a new menu item to the Add-ons menu. This new menu item has the text 'no name'.
Now, we're adding this lines of code:
Doing this, we give the menu item a name, a shortcut, and we set it to color red:
Now we can add the MenuItem a event handler:
As you can see, adding an event handler to a MenuItem its far easy! It's done as it would be done on any other .net control. Just create a Sub with the appropriate signature and link the sub with the event with the AddHandler sentence.
That's all for this first tutorial!!
|