LoadResPicture Function

Syntax

LoadResPicture(resID, resType)


resID

Use: Required

Data Type: Variant

A numeric or string value specifying the resource ID of the picture to load.


resType

Use: Required

Data Type: Variant

A numeric constant denoting the format of the picture to load. See the following table for valid constants and values:

Constant Value Description
vbResBitmap 0 Bitmap resource
vbResIcon 1 Icon resource
vbResCursor 2 Cursor resource

Return Value

An IPictureDisp interface.

Description

Assigns a graphic from a resource file (.RES ) to the Picture property of a form or control.

Rules at a Glance

  • The images to be loaded by LoadResPicture must be included in a resource (.RES ) file. Each must be assigned a unique identifier, which is typically represented by a numeric constant.

  • The file loaded by LoadResPicture can be a Windows bitmap file (.BMP or .RLE), an icon file (.ICO), or a cursor file (.CUR ).

  • The image returned by the LoadResPicture function can be assigned to any form or control property that expects an StdPicture object. These include the Picture property of a PictureBox or an Image control, the Icon property of a Form object, or the MouseIcon property of a form.

Programming Tips and Gotchas

  • LoadResPicture is part of the VB Runtime Library and, as such, isn't available in VBA applications.

  • Visual Basic 6 includes an add-in Resource Editor; see the previous sidebar for more information.

  • Using graphics from a .RES file speeds up the loading of a form.

Example

In this example, bitmaps that denote the type of employee have been stored in a resource file. A Select Case statement then determines which bitmap should be loaded into the Picture property of the current grid cell. The advantage of using this method to load pictures is that the graphic is loaded only as it's needed, as opposed to the traditional method of loading all possible pictures into hidden controls on the form, which slows the loading of the form.

Private Function RefreshEmployeeGrid(iEmployeeType _
                                     As Integer)
   Select Case iEmployeeType
      Case Is = MAINT_SERV
         grdEmp.Picture = LoadResPicture(102, vbResBitmap)
      Case Is = PRODUCTION
         grdEmp.Picture = LoadResPicture(103, vbResBitmap)
      Case Is = CLERICAL
         grdEmp.Picture = LoadResPicture(104, vbResBitmap)
   End Select
    
End Function

You could enhance this example by making the ID of each bitmap resource identical to the iEmployeeType value, so that you could replace the Select Case construct with just one line of code:

grdEmp.Picture = LoadResPicture(iEmployeeType, vbResBitmap)

See Also

LoadResData Function, LoadResString Function
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset