Profile Facebook Twitter My Space Friendster Friendfeed You Tube
Kompas Tempo Detiknews
Google Yahoo MSN
Blue Sky Simple News Simple News R.1 Simple News R.2 Simple News R.3 Simple News R.4

Posts Recentes

Saturday, October 18, 2008 | 10:15 PM | 0 Comments

Include Pictures In Your Visual Basic Application



If you are writing a visual basic application that you intend to sell, and you want to include image files within the program and have the image change based on a selection from something like a listbox or an option button, you’ll need to retrieve the files from another location. This article shows a convenient way to accomplish this.

If you want to display CAD files, or other images and pictures, within your visual basic application, there are a number of ways to accomplish this. If you are displaying a static picture (one that doesn't change),you can just load it into a picture box.

There are several ways to store and call graphics files to display based upon a user selection, using the "Image" feature. However, there are disadvantages to at least two of the most obvious methods.

You can include the graphics files in your .cab file, and have them load into the applications working directory. The problem with this is that if the files get lost, it causes a run-time error in your application, and your user will not be happy. Basically, this can cause your program to crash because your application calls for a file that is no longer there.

You can use the visual basic recommended method of storing and retrieving your files from a resource file. The problem with this is that the resource file feature will only accept bitmap image files. The bitmaps tend to be rather large in file size, but more importantly, the image quality is poor.

I have found that Windows meta files (*.wmf) work best when trying to display images created in a CAD system. These images, when loaded into an "Image" box, can be made to automatically "stretch", or scale, themselves to fit the box provided. This way, your images don't have to be all exactly the same size to look proportionate. In addition, the image resolution is much beter than a bitmap file.

Image provided by DZynSource, LLC Let's assume that you are writing an application, and you want to call various pictures to one "Image" box displayed on a form. Let's further assume that you want the image to change based on a user selection, like the form shown in the picture to the left. Once your image files are created, and saved in Windows Meta File format, they are ready to be imported into your application.

Create a form called something like "frmPicture". Add as many picture boxes as you desire to this form. Click on a picture box, go to the "properties" dialog box, and name the picturebox with a name that is something meaningful to you. If you are going to show pictures of a car, you could call this picture box "car", for example.

While in the properties dialog box, scroll down to the "picture" property. When you click on the picture name, in the properties column, a command button with three dots on it appears at the end of the picture property row. Click on it. This opens a direcory list box that allows you to search your computer to find your files. Select your desired car picture file. The picture will display in the picture box that you just created.

Now go to the form where you want to display these interchangeable pictures. Create an "Image" box, and size it to suit your application. Call this image box "Image1", or whatever makes sense to you. Go to the Properties dialog box and set the stretch property equal to true.

We use an Image box here because it has this property called "stretch" that allows our pictures to re-size to fit the box created.

If you are going to use an option button to select the image to be displayed, you can use code like the following to retrieve the picture:

Private Sub optCar_Click()
If optCar.Value = True Then

Set Image1.Picture = frmPicture.Car.Picture
Image1.Refresh

You can change the code to suit whatever selction feature and file names you decide to use.

This tells the program that Image1's picture property is the car picture from the form called frmPicture.

In this case, every time the user selects a different option button, based on the textual description next to the button, the image changes to show a graphical representation of the choice. This is a visual aid to the user, and makes the software interface more user friendly.

Using this method accomplishes several things:

The images are internal to your application, that is, they are contained within the application.
You don't have to ship pictures and images as separate files that can get lost from the root directory, and ruin the performance of your software.
The Windows meta files give a reasonably good image quality, and scale to fit the image box supplied.

0 comments:

 
Copyright © 2010 - All right reserved | Template design by Herdiansyah Hamzah | Published by Jurnalborneo.com
Proudly powered by Blogger.com | Best view on mozilla, internet explore, google crome and opera.