Adding Buttons to the Toolbar
At the heart of a normal button is the Label/Value, the width & height, the type of button it is and the click event.
There is a variety of buttons that you can create: These are depicted in this enumeration class.
Code:
Public ButtonBase As String = ""
Public ButtonDanger As String = "danger"
Public ButtonForm As String = "form"
Public ButtonPrev As String = "prev"
Public ButtonNext As String = "next"
Public ButtonImage As String = "image"
Public ButtonIconButton As String = "iconButton"
Public ButtonIconButtonTop As String = "iconButtonTop"
Public ButtonImageButton As String = "imageButton"
Public ButtonIcon As String = "icon"
This means we can add icons to buttons, add images, theme them to be 'red for danger' etc. This basically indicates the 'type' of element and will go to the wixelement.type property.
In the gif on the first post we have covered the normal buttons, image, iconbutton, iconbuttontop, imagebutton and icons.
There are two methods to add buttons to the toolbar...
1. either we initialize it and then add it to the toolbar
2. either we use the
.CreateButton / .CreateToggle / .CreateIcon methods of the toolbar and then .Pop these to the toolbar.
The New Button
Code:
tblBar.CreateButton("btnNew").SetLabel("New").SetIcon("file").SetClick(BANano.CallBack(Me,"btnnew_click",Null)).SetBatch(1).Pop
The new button is created using the toolbar CreateButton method. We id the button is btnNew, then set its label/value to New. We then set its icon () using .SetIcon.
After that we bind a click event to it using a BANano.Callback call. The method to be called when the button is clicked is
btnnew_click.
When we were creating the toolbar, we indicated that the visibleBatch should be 1. So setting the batch number to 1 for this button will ensure that it shows.
Using .CreateButton ensures that the parent element of the component is linked, thus its easy to have a method like .Pop to populate the button and add it to the Columns collection of the toolbar.
The Open Button
The Open button is created via the second method, ie. initialize the button and then add it to the toolbar.
Code:
Dim btnOpen As WixButton
btnOpen.Initialize("btnOpen").SetLabel("Open").SetIcon("folder-open").SetBatch(2).SetClick(BANano.CallBack(Me,"btnopen_click",Null)).AddToToolbar(tblBar)
'
Nothing is very different from the calls we made earlier to create the new button except for .SetBatch(2) and .AddToToolBar(tblBar) here. We initialized the button and set some properties and then added it to the toolbar. Because the batch number of this button is 2 and our .SetVisibleBatch = 1 this button will not be shown on creation as its a child element of the toolbar with a different visible batch number.