
Bug: drawing/resizing a PictureBox eat up GDI Resources on Win95
I've reproduced this, somewhat, with the following code. I placed a
picturebox, set to AutoRedraw = True, an ImageList, and a button on a
form and put this code in the button click event:
Private Sub Command1_Click()
Dim i As Long
'loses about 4% GDI memory each click
For i = 1 To 50
Picture1.Cls 'leaks
'Picture1.Picture = LoadPicture() 'leaks
'Picture1.Line (0, 0)-Step(Picture1.ScaleWidth,
Picture1.ScaleHeight), Picture1.BackColor, BF 'no leak!
Picture1.Line (Rnd * 100, Rnd * 100)-Step(Rnd * 700, Rnd * 700), 0&
ImageList1.ListImages.Add , , Picture1.Image
Next i
End Sub
Resizing the picturebox does not seem to affect the results.
The problem is in the .Cls: simply drawing a filled box in the
backcolor over the whole picturebox instead of clearing it cures the
resource leak. I did this in Win95, VB5 SP2, HighColor (16-bit) video.
Jim Deutch
MS Dev MVP
Quote:
> Hi everybody,
> we use the PictureBox Control with VB5 to extensivly create dynamical
images
> and copy the images to a grid control. Multiple drawing/resizing the same
> PictureBox results in 'out of GDI memory resources' error messages. What
> alternative control we could use instead?
> Any suggestions are welcome!
> Torsten