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:

 

Imports BLIde.SDK

Public Module Plugin

   Sub Main()

       IO.Msg("If you see this message, you've set up the VS project properly!", "Hello world!")

   End Sub

End Module

 

First of all, as our plugin is not intended to be a Hello World message, we'll delete the IO.Msg sentece, this way:

 

Imports BLIde.SDK

Public Module Plugin

   Sub Main()

 

   End Sub

End Module

 

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.

 

Imports BLIde.SDK

Public Module Plugin

   Sub Main()

       Dim MenuItem As BLIde.SDK.BLIdeForms.BLIdeMenuItem

   End Sub

End Module

 

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:

 

Imports BLIde.SDK

Public Module Plugin

   Sub Main()

       Dim MenuItem As BLIdeForms.BLIdeMenuItem

       MenuItem = New BLIdeForms.BLIdeMenuItem(Api.AddOnsBarItem)

   End Sub

End Module

 

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:

 

tutorial1-1

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:

 

Imports BLIde.SDK

Public Module Plugin

   Sub Main()

       Dim MenuItem As BLIdeForms.BLIdeMenuItem

       MenuItem = New BLIdeForms.BLIdeMenuItem(Api.AddOnsBarItem)

       MenuItem.Text = "Hello world!"

       MenuItem.Shortcut = Windows.Forms.Shortcut.CtrlR

       MenuItem.ForeColor = Drawing.Color.Red

   End Sub

End Module

 

Doing this, we give the menu item a name, a shortcut, and we set it to color red:

 

tutorial1-2

 

Now we can add the MenuItem a event handler:

 

Imports BLIde.SDK

Public Module Plugin

   Sub Main()

       Dim MenuItem As BLIdeForms.BLIdeMenuItem

       MenuItem = New BLIdeForms.BLIdeMenuItem(Api.AddOnsBarItem)

       MenuItem.Text = "Hello world!"

       MenuItem.Shortcut = Windows.Forms.Shortcut.CtrlR

       MenuItem.ForeColor = Drawing.Color.Red

 

       AddHandler MenuItem.Activate, AddressOf ClickMenuItem

 

   End Sub

   Sub ClickMenuItem(ByVal sender As Object, ByVal e As System.EventArgs)

       IO.Msg("Hello world!!")

   End Sub

 

End Module

 

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!!