In this article we will learn how to add and use Toolbar Control in REALbasic project. Article covers the following topics: adding a item (push button, icon, separator, space) to Toolbar, adding actions on item click, adding a popup menu to Dropdown button. Watch it, learn it, enjoy it!
We start this tutorial with adding Toolbar Control to our REALbasic Project. We do this by clicking on Add Toolbar button available in Project Tab.

To add items to REALbasic Toolbar control we double click on Toolbar1 in Project Tab and we should be in place similar to screenshot below. Now click on Add Tool item five times and set (in item Property and Value) for ToolItem1 Style = 0 Push button, ToolItem2 Style = 1 Separator, ToolItem3 Style = 2 Toggle button, ToolItem4 = 5 Space, ToolItem5 = 3 Dropdown button. You can also set the buttons text in Caption (I called items after the name of style). You can also add some graphics to the items. To do this look for icon property for selected Toolbar item.

The last thing before writing the code we will insert the Toolbar Control from Window1 GUI builder Control Panel. Go to Window1 and drag and drop from All Controls Toolbar1 to our application Window.

To make something happen when the user will click on one of Toolbar items we must add some code to Toolbar1 Sub Actions () in Code Editor. We can do this by Item Name or by Item Caption. In this step we will use the first option.
1 2 3 4 5 6 7 8 | select case item case me.ToolItem1 MsgBox "Push button item was pressed" case me.ToolItem3 MsgBox "Toggle button item was pressed" end select |
There can be a problem when you like to use item style Dropdown button… To get it work we must create a new MenuItem and attach it to this button style. Go to Toolbar1 Sub Open () and insert there:
1 2 3 4 5 6 7 8 9 10 11 | Dim myMenu as New MenuItem Dim myMenu1 as New MenuItem Dim myMenu2 as New MenuItem MyMenu1.Text="REALbasic CIty" MyMenu2.Text="qbap" MyMenu.Append myMenu1 MyMenu.Append myMenu2 me.ToolItem4.DropdownMenu = myMenu |
Now we should make some events when the user will click on any MenuItem in Dropdown button. Go to Toolbar1 Sub DropDownMenuAction () and enter:
1 2 3 4 5 6 7 8 | select case hititem.Text case "qbap" MsgBox "You chose qbap" case "REALbasic City" MsgBox "You chose REALbasic City" end select |
Great!!!