Microsoft KB Archive/153928

= How To Put a ComboBox into a Toolbar =

Article ID: 153928

Article Last Modified on 3/15/2005

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
 * Microsoft Visual Basic for Applications 5.0

-



This article was previously published under Q153928



SUMMARY
This article describes how to use the Toolbar control in the 32-bit version of Visual Basic 4.0 to allow programmers to add buttons to the Toolbar but not ComboBoxes. If you create a ComboBox at design time and place it on top of the Toolbar, the ComboBox will not appear when the program is run. This behavior occurs because the Toolbar has a higher precedence than the ComboBox on the Z-order.

To put a ComboBox on a Toolbar, create a button on the Toolbar to act as a place holder, and position the ComboBox above the place holder in the Z-order, because you cannot place the ComboBox inside the place holder directly.

The following code sample showing how this effect can be achieved.



MORE INFORMATION
 Start a new Visual Basic project. Form1 is created by default. Place a ComboBox on the form. Place a Toolbar on the form.  Add the following code to the Form1 code window: Option Explicit

Private Sub Form_Load Dim btn As Button Me.Show Set btn = Toolbar1.Buttons.Add btn.Style = tbrSeparator Set btn = Toolbar1.Buttons.Add btn.Style = tbrPlaceholder btn.Key = "ComboBox" btn.Width = 2000

DoEvents

With Combo1 .ZOrder 0 .Width = Toolbar1.Buttons("ComboBox").Width .Top = Toolbar1.Buttons("ComboBox").Top .Left = Toolbar1.Buttons("ComboBox").Left End With End Sub

 Press the F5 key to run the project. The Form should load with a ComboBox in the Toolbar.

Additional query words: kbVBp400 kbVBp600 kbVBp kbdsd kbDSupport kbControl

Keywords: kbhowto kbcontrol KB153928

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.