Microsoft KB Archive/170341
Article ID: 170341
Article Last Modified on 6/29/2004
- Microsoft Visual Basic 5.0 Learning Edition
- Microsoft Visual Basic 4.0 Professional Edition
- Microsoft Visual Basic 5.0 Professional Edition
- Microsoft Visual Basic 4.0 Enterprise Edition
- Microsoft Visual Basic 5.0 Enterprise Edition
This article was previously published under Q170341
When using the LoadPicture Function to display a 16 x 16 icon in an Image control, or any other control that uses the LoadPicture function to store images into the Picture object, the icon will display at 32 x 32.
To work around this problem, use one of the following methods.
- Use a 16 x 16 bitmap instead of an icon. -or-
Use an Image Control and set the Height and Width to be the same as the icons. For example:
Image1.Picture = LoadPicture(<path to your icon>) Image1.Stretch = True 'Needed so the image does not get clipped 'The next two lines assume that the form's ScaleMode is Twips 'It changes the Image control to be 16 x 16 Pixels Image1.Width = (Screen.TwipsPerPixelX * 16) Image1.Height = (Screen.TwipsPerPixelY * 16)
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been fixed in Visual Basic 6.0.
LoadPicture always loads a 32 x 32 icon. If the icon file being loaded contains a single 16 x 16 image, LoadPicture stretches it to 32 x 32 before storing it in the Picture object of a control.
Steps to Reproduce Behavior
The steps below illustrate an example that displays a 16 x 16 icon in an Image control.
NOTE: You can use IMAGEDIT.EXE that ships on the Visual Basic 5.0 CD-ROM to create icons. This tool is located in the Tools\Imagedit directory on the Visual Basic 5.0 CD-ROM.
- Create a new project. Form1 is created by default.
- Place an Image control on Form1.
Add the following code to Form1:
Private Sub Form_Load() Image1.Picture = LoadPicture(<Path to your 16 x 16 icon>) End Sub
- Run the form by choosing Start from the Run menu. Note that the icon is displayed as a 32 x 32 icon.
"HardCore Visual Basic", Microsoft Press, pg. 535
Additional query words: kbVBp500bug kbVBp400bug kbVBp600fix kbVBp kbdsd kbDSupport kbControl
Keywords: kbbug kbfix kbprb KB170341