Resource Files

Using A Resource File

In this exercise, you will use a resource file within your application.

  1. Start Microsoft Visual Basic 5 and create a new Standard EXE project.
  2. Add controls to the form as shown below. Do not change the control's default names .

  1. 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.
  2. Add code to the Exit button's click event to end the application.
  3. Save your work as Form1.frm and Lab04.vbp in the WA\Practice\Ch04 folder.
* To use a resource file in Visual Basic
  1. 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.

  2. In the Project Explorer, double-click Related Documents to verify the resource file has been added to this project.
  3. Open the code window for the Form_Load event.
  4. Add the following code to load resource picture 100 and assign it to the Image control's Picture property.
     Image1.Picture = LoadResPicture(100, vbResIcon) 
  5. Load resource string 100 and assign it to the Label control's Caption property.
     Label1.Caption = LoadResString(100) 
  6. Run the application.

If the resources are loaded correctly, your form should resemble the following:

  1. Change the code in Form_Load to use the picture and string resources numbered 200.
  2. Run the application.


Microsoft Windows Architecture Training
Microsoft Windows Architecture for Developers Training Kit
ISBN: B00007FY9D
EAN: N/A
Year: 1998
Pages: 324

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net