How to Make a Gallery of Images in Visual Basic 6.0
- 1). Click "Project" on the menu and then click "Components" from the drop down list, or press "CTRL+T" on the keyboard to open the Components menu. Scroll down to "Microsoft Windows Common Controls 6.0 (SP6)" and click the check box beside it. Click "OK." This adds several new tools to the toolbox, including the ImageList control.
- 2). Double-click the ImageList control in the toolbox to add one to your form. Click on the ImageList on your form and double-click the "(Custom)" option from the Properties window. This opens up a dialogue box for your images.
- 3). Click on the "Images" tab. Click on "Insert Picture" and navigate to your pictures. Double click on the one you need to load it into your ImageList. Repeat this process to upload all of the pictures you need. Click "OK" to close the box.
- 4). Double-click the "Image" control in the toolbox to add one to your project. Click and drag its edges to resize it if necessary. Change the "Stretch" property to "True."
- 5). Add two CommandButton controls from the toolbox to your form. Change the "Caption" property of the first to "Previous" and of the second to "Next." Arrange your controls on your form. Your ImageList control will not show at run time, so you can leave it wherever you prefer.
- 6). Open the code window. Create a global count variable by typing "Dim picNum As Integer" under "Option Explicit." Access your "Form_Load()" function. Type "picNum = 1" on the first line and "Image1.Picture = ImageList1.ListImages.Item(picNum).Picture" on the next line. This will load the first image in your ImageList into your Image box.
- 7). Open the code for your "Next" command button and type the following lines:
If Not picNum = ImageList1.ListImages.Count Then
picNum = picNum + 1
Else
picNum = 1
End If
Image1.Picture = ImageList1.ListImages.Item(picNum).Picture - 8). Open the code for your "Previous" command button and type the following lines:
If Not picNum = 1 Then
picNum = picNum - 1
Else
picNum = ImageList1.ListImages.Count
End If
Image1.Picture = ImageList1.ListImages.Item(picNum).Picture - 9). Run your program and test your buttons. The image control will display an image from your ImageList. Cycle through the images by clicking the Previous and Next command buttons.
Source...