The information in this article applies to:
- Standard, Professional, and Enterprise Editions of Microsoft Visual
Basic, 32-bit only, for Windows, version 4.0
SYMPTOMS
The Count property value of the Toolbar Buttons collection is not correct
when a button without an image is shown on the Toolbar control.
CAUSE
This behavior occurs if an Invalid image parameter is used with the Add
method on an ImageList control. The ImageList control supplies the images
for the buttons on the Toolbar control.
STATUS
Microsoft has confirmed this to be an issue in the Microsoft products
listed at the beginning of this article. Microsoft is researching this
issue and will post new information here in the Microsoft Knowledge Base
as it becomes available.
WORKAROUND
Use a valid Image index number.
-or-
If you want a button to show without an image, trap the error and leave
out the Image parameter in the Add method.
MORE INFORMATION
Steps to Reproduce Problem
- Start the 32-bit edition of Visual Basic 4.0. If it is already running,
from the File menu, select New Project.
- Add a Toolbar control, an Image List control, and a Command button to
Form1.
- Copy the following code to the Code window of Form1:
Option Explicit
Private Sub Command1_Click()
Dim i As Integer
Dim ImgX As ListImage
Dim tbButton As Button
Set ImgX = ImageList1.ListImages.Add(, , _
LoadPicture("C:\Visual Basic\Icons\Industry\bicycle.ico"))
' Modify the argument for the LoadPicture function to point to
' directory containing an icon.
On Error Resume Next
Form1.Toolbar1.ImageList = ImageList1
' Comment the next line to workaround problem.
Set tbButton = Form1.Toolbar1.Buttons.Add(1, , "Node1", , 2)
' Uncomment one of the following lines to workaround problem.
' Uncomment this line if you want the image to appear on the
' button.
' Set tbButton = Form1.Toolbar1.Buttons.Add(1, , "Node1", , 1)
' Uncomment this line if you want a blank button
' Set tbButton = Form1.Toolbar1.Buttons.Add(1, , "Node1")
MsgBox "Number of Buttons according to Count Property: " & _
Toolbar1.Buttons.Count
End Sub
- On the Run menu, select Start, or press the F5 key. Click the Command
button. A button appears on the Toolbar but the message box indicates
no buttons on the Toolbar.
|