BUG: Controls Cannot Be Added to Toolbar Programmatically

Last reviewed: August 5, 1997
Article ID: Q172343
The information in this article applies to:
  • Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 5.0 on the following platforms: NT, Win95
  • Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit only, for Windows, version 4.0 on the following platforms: NT, Win95
  • Microsoft Visual InterDev, version 1.0 on the following platforms: NT, Win95

SYMPTOMS

With Visual Basic, you may add controls to a Toolbar control by creating a placeholder button on the toolbar and then setting the control to the same position. If you use the Comctl32.ocx that ships with Visual Studio 97 and Visual Basic 5.0, the control may unexpectedly appear behind the toolbar.

RESOLUTION

To work around this problem, create a pause with DoEvents after you set all the controls in place and then set the Toolbar control to the bottom of the ZOrder.

NOTE: This workaround does not apply to non-windowed controls, such as a

      Label or a Shape. To use this workaround with non-windows controls,
      the controls must be contained in a PictureBox.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start a new Visual Basic project.

  2. Click Components on the Project menu and check "Microsoft Windows Common Controls 5.0."

  3. Add a Toolbar control and a ComboBox control to Form1.

  4. Add the following code to Form1:

          Private Sub Form_load()
    

          Dim btn As Button
    

             Me.Show
    
             'Add a separator to the toolbar
             Toolbar1.Buttons.Add Style:=tbrSeparator
    
             'Add a Placeholder to the toolbar.
             Set btn = Toolbar1.Buttons.Add(Key:="ComboBox", _
                Style:=tbrPlaceholder)
             btn.Width = 2000
    
    'Place the combo box on top of the Placeholder
             With Combo1
                .Width = btn.Width
                .Top = btn.Top
                .Left = btn.Left
                .ZOrder 0
             End With
    
          End Sub
    
    

  5. Press F5 to run the application. Notice that Combo1 does not appear over the Placeholder on Toolbar1.

  6. To correct this problem, add the following code just before End Sub of the Form_Load event procedure.

          DoEvents
          Toolbar1.ZOrder 1
    

Keywords          : PrgCtrlsStd vb5all
Version           : WINDOWS:1.0,4.0,5.0
Platform          : WINDOWS
Issue type        : kbbug


================================================================================


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: August 5, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.