Loading and Displaying an Image (Visual Basic)

Take the following steps to start a project and to add some code that displays an image on the main form:

1. Start Visual Basic.

2. Add the LEAD Main ActiveX Control to your project.

For VB4: On the Tools pull-down menu, use the Custom Controls option, and select the LEAD OLE Custom Control (16).

For VB5: On the Project pull-down menu, use the Components option, and select the LEAD Main ActiveX Control (16).

3. image\btnlead.gif Select the LEAD Main ActiveX control; then add the control to your main form. Size and position the control as you want it to appear at run time.

4. image\btncmd.gif Add a command button to your form and name it as follows:

Name Caption

LoadLead Load Image

5. Add the following initialization code to the main form's Load procedure. In online help, you can use the Edit pull-down menu to copy the block of code.

Private Sub Form_Load()
  'Set defaults for displaying the image.
  'These are all persistent properties that can be set in the properties box.
  Lead1.Appearance = APPEARANCE_FLAT
  Lead1.BorderStyle = 1
  Lead1.BackColor = RGB(255, 255, 125)
  Lead1.PaintDither = PAINTDITHER_DIFFUSION
  Lead1.PaintPalette = PAINTPALETTE_AUTO
  Lead1.AutoRepaint = True
  Lead1.AutoSize = False
  Lead1.AutoSetRects = True
  Lead1.PaintSizeMode = PAINTSIZEMODE_FIT
End Sub

6. Code the LoadLead button's click procedure as follows:

Private Sub LoadLead_Click()
    Lead1.Load "c:\lead\images\image1.cmp", 0, 0, 1
End Sub

7. Run your program to test it.

8. Save the project to use as a starting point for other tasks in this tutorial.