One of the common non-button controls you see in toolbars is the combo box control, which lets the user select an item from a list, or type their own entry. In previous versions of Visual Basic, it was difficult to add combo boxes or other such controls to a toolbar, but now it's easy. All you have to do is to leave space in the toolbar for the combo box or other control, and then place a combo box in that space. You can leave space in a toolbar by using separator buttons-that is, toolbar buttons whose style has been set to Separator.
That's what I've done in the ToolBars example on the CD-ROM-created some space in the toolbar using multiple separators and placed a combo box, ComboBox1, in that space. I've also added a few items to the combo box, Red, Blue, and Green, and added this code to its SelectedIndexChanged event handler:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim selectedIndex As Integer selectedIndex = ComboBox1.SelectedIndex Dim selectedItem As Object selectedItem = ComboBox1.SelectedItem MsgBox("Selected item text: " & selectedItem.ToString() & _ " Selected index: " & selectedIndex.ToString()) End Sub
You can see the results of this code in Figure 10.4, where you see the combo box in the toolbar. Besides combo boxes, you can add all kinds of other controls to toolbars as well.