HOWTO: Put a ComboBox into a Toolbar

Last reviewed: June 9, 1997
Article ID: Q153928
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0

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.

Below is a code sample showing how this effect can be achieved.

MORE INFORMATION

  1. Start a new Visual Basic project. Form1 is created by default.

  2. Place a ComboBox on the form.

  3. Place a Toolbar on the form.

  4. 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
          With Combo1
             .ZOrder 0
             .Width = Toolbar1.Buttons("ComboBox").Width
             .Top = Toolbar1.Buttons("ComboBox").Top
             .Left = Toolbar1.Buttons("ComboBox").Left
          End With
       End Sub
    
    

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


Keywords : kbusage PrgOther vb4all vb4win kbhowto
Version : 4.0
Platform : NT WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 9, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.