HOME   DOWNLOADS   ORDER ONLINE   CONTACT US



 OVERVIEW
 
 DOWNLOAD
 
 ORDER ONLINE
 
 KNOWLEDGE
 BASE

Problems with pictures?

Enter the sample code below. You will need to draw an SBList on your form and set its TextLeft property to 15. You will also need a Picture box 210x210 twips in size, with its ScaleMode property set to 3 (pixels) and its AutoRedraw property set to True.

Insert the following code into your Form_Click event:

For A% = 0 To 15
  Picture1.Line (0, 0)-(10, 10), QBColor(A%), BF
  SBList1.AddPacket -1, "QBColor" & A%, "", , _
     Picture1.Image
Next A%
The logic of it should produce a list of 16 items showing the QBColor shade and value of each item when you click the form:

However, as you will see when you run it you actually end up with a list where all the images are white. To see exactly what is going on, modify the code above to read:

For A% = 0 To 15
  Picture1.Line (0, 0)-(10, 10), QBColor(A%), BF
  SBList1.AddPacket -1, "QBColor" & A%, "", , _
      Picture1.Image
  T# = Timer + .5
  Do While Timer < T#
    DoEvents
  Loop
Next A%
Now run the program again, and you will see that the picture box is in fact changing colour correctly, but after each change it affects all the images already displayed in the list. When this feature was discovered we decided to leave it in just in case it had some useful application! Besides, it's easy to program around it - simply add the line:

Picture1.Cls
at the beginning of the loop and the problem is solved.

Why does this happen? When you add a picture to SBList, the picture is linked to the list item by a reference number. When you perform a destructive operation on the source picture (like Cls or LoadPicture), the image and reference number are frozen and stored in memory so that your list image doesn't change when the source image is destroyed. In the first block of code above, the same reference number is being used for all 16 list items because the Line operation is not a destructive one - if it was, you could only ever draw one line on a picture control!

Topic devised by Andy Groom.

 
Copyright © 2000 Global Components. All rights reserved.