Load UI Graphics From the Resource File

Many VB programmers haven’t harnessed the power of VB6’s resource editor. They still use traditional LoadPicture or other primitive calls to load bitmaps and icons. Before VB5, loading pictures into controls was somewhat harder, because of the inherent troubles associated with specifying the path and filename of the resource. With the resource editor, it’s easy to store icons, strings, and bitmaps in a single RES file. I had to load the same picture for several CommandButton controls in a current project. I set the Style property of the CommandButton to 1 (Graphical) and the Tag property to “calendar” so my app would know to load calendar.bmp. I then added and saved this BMP in a resource file and set the ID to “calendar.” First paste this code into the general section of a form:

 'loads icons/bmps from resource files.Sub FillPictures(psdFrm As Form)	' desired form is passed as an parameter.	Dim lcl_Ctrl As Control	For Each lcl_Ctrl In psdFrm.Controls		' controls collection is used here.		If LCase(lcl_Ctrl.Tag) = "calendar" Then		' checking the tag property.			Set lcl_Ctrl.Picture = _				LoadResPicture(lcl_ctrl.tag, vbResBitmap)		End If		' extra code could have been added for 		' loading other picture files by setting 		' the tag property accordingly.	NextEnd Sub

Then call this function from the Form_Load event:

 Private Sub Form_Load()	Call FillPictures(Me)End Sub
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: