Load UI Graphics From the Resource File

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
See also  How HealthStream Learning Center Supports Healthcare Education and Compliance

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist