Using A Resource File
In this exercise, you will use a resource file within your application.
- Start Microsoft Visual Basic 5 and create a new Standard EXE project.
- Add controls to the form as shown below. Do not change the control's default names .
- The control in the upper-left corner is an image control. Put any icon you wish in the Picture property. Icons are provided in the Visual Basic Graphics\Icons directory.
- Add code to the Exit button's click event to end the application.
- Save your work as Form1.frm and Lab04.vbp in the WA\Practice\Ch04 folder.
* To use a resource file in Visual Basic - From the WA\Practice\Ch04 directory, add the resource file named Lab.res to the project.
To add the resource file, right-click the Project Explorer and click Add . Click Add File to browse for the resource file.
- In the Project Explorer, double-click Related Documents to verify the resource file has been added to this project.
- Open the code window for the Form_Load event.
- Add the following code to load resource picture 100 and assign it to the Image control's Picture property.
Image1.Picture = LoadResPicture(100, vbResIcon)
- Load resource string 100 and assign it to the Label control's Caption property.
Label1.Caption = LoadResString(100)
- Run the application.
If the resources are loaded correctly, your form should resemble the following:
- Change the code in Form_Load to use the picture and string resources numbered 200.
- Run the application.