Microsoft KB Archive/172343

= FIX: Controls Cannot Be Added to Toolbar Programmatically =

Article ID: 172343

Article Last Modified on 6/24/2004

-

APPLIES TO

 Microsoft Visual Basic 5.0 Learning Edition, when used with:  Microsoft Windows NT 4.0

 Microsoft Windows 95  Microsoft Visual Basic 6.0 Learning Edition, when used with:  Microsoft Windows NT 4.0

 Microsoft Windows 95</li></ul> </li> Microsoft Visual Basic 5.0 Professional Edition, when used with:  Microsoft Windows NT 4.0</li></ul>

 Microsoft Windows 95</li></ul> </li> Microsoft Visual Basic 6.0 Professional Edition, when used with:  Microsoft Windows NT 4.0</li></ul>

 Microsoft Windows 95</li></ul> </li> Microsoft Visual Basic 5.0 Enterprise Edition, when used with:  Microsoft Windows NT 4.0</li></ul>

 <li>Microsoft Windows 95</li></ul> </li> <li>Microsoft Visual Basic 6.0 Enterprise Edition, when used with: <ul> <li>Microsoft Windows NT 4.0</li></ul>

<ul> <li>Microsoft Windows 95</li></ul> </li> <li>Microsoft Visual Basic 4.0 Standard Edition, when used with: <ul> <li>Microsoft Windows NT 4.0</li></ul>

<ul> <li>Microsoft Windows 95</li></ul> </li> <li>Microsoft Visual Basic 4.0 Professional Edition, when used with: <ul> <li>Microsoft Windows NT 4.0</li></ul>

<ul> <li>Microsoft Windows 95</li></ul> </li> <li>Microsoft Visual Basic 4.0 32-Bit Enterprise Edition, when used with: <ul> <li>Microsoft Windows NT 4.0</li></ul>

<ul> <li>Microsoft Windows 95</li></ul> </li> <li>Microsoft Visual InterDev 1.0 Standard Edition, when used with: <ul> <li>Microsoft Windows NT 4.0</li></ul>

<ul> <li>Microsoft Windows 95</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q172343

<div class="symptoms_section">

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, or MSCOMCTL.OCX that ships with Visual Studio 6.0 and Visual Basic 6.0, the control may unexpectedly appear behind the toolbar.

<div class="resolution_section">

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.

<div class="status_section">

STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. For Visual Studio 6.0 and Visual Basic 6.0 using MSCOMCTL.OCX, this behavior has been resolved with Service Pack 3.

<div class="moreinformation_section">

Steps to Reproduce Behavior
<ol> <li>Start a new Visual Basic project.</li> <li>Click Components on the Project menu and check "Microsoft Windows Common Controls 5.0."</li> <li>Add a Toolbar control and a ComboBox control to Form1.</li> <li> Add the following code to Form1: Private Sub Form_load

Dim btn As Variant

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 </li> <li>Press F5 to run the application. Notice that Combo1 does not appear over the Placeholder on Toolbar1.</li> <li> To correct this problem, add the following code just before End Sub of the Form_Load event procedure: DoEvents Toolbar1.ZOrder 1

</li></ol>

Keywords: kbbug kbfix kbcontrol kbvs600sp3fix KB172343

-

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

© Microsoft Corporation. All rights reserved.