This instructable will show you how to program Microsoft Visual Basic 2005 Express Edition. The example that you will create today is a simple image viewer.
If you like this instructable please push the + button at the top of the instructable. Thanks.
Also, I think I will be like half the other instructables out there and say that this is my first instructable and please don't be to harsh.
EDIT: Once you have completed this instructable, continue learning VB with my second Visual Basic Instructable: Creating a Program in Visual Basic: Web Browser
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Download Visual Basic
You can download visual basic 2008 from microsoft but this instructable is specificly for VB 2005 wich you can download from freeware files
EDIT: It is now recommended you VB 2008, as I will use it for any future tutorials. Link
Please note: you will still need to be connected to the internet during the install.
Step 2: Create Your Project.
Click File->New Project. Select "Windows Application". Give your project a name.
Step 3: Add Controls
From the tools box, drag a picture box onto your form, drag a button onto your form and drag an open file dialog onto your form.
Step 4: Edit Control Properties
- Text: Picture Viewer
- Form Border Style: Fixed Tool Window
- Background Image Layout: Zoom
- Text: Select Image
Step 5: Add Code
Public Class Form1 Private pic As Bitmap Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click OpenFileDialog1.FileName = "Select File" OpenFileDialog1.ShowDialog() pic = New Bitmap(OpenFileDialog1.FileName) PictureBox1.BackgroundImage = pic End SubEnd ClassEnd Code
WHAT THE CODE DOES
Public Class Form1 - Defines the form as Public
Private pic As Bitmap - Defines pic As a private bitmap
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click - Defines When The Events Should Occur
OpenFileDialog1.FileName = "Select File" - Makes the file name in the OpenFileDialog say Select File
OpenFileDialog1.ShowDialog() - Shows the OpenFileDialog
pic = New Bitmap(OpenFileDialog1.FileName) - Adds the value of the selected image to pic
PictureBox1.BackgroundImage = pic - Changes the image in ImageBox1 to pic
Step 6: Save and Test
Save your program (File->Save All) and click the green play button on the toolbar to debug your program. If all goes well then you should be able to use the program.
The final program is stored in 'My Documents/Visual Studio 2005/Projects/PROJECT NAME/PROJECT NAME/Bin/Debug/PROJECT NAME.exe'
(Where PROJECT NAME is the name of the project)
Step 7: Final Thoughts
Congratulations on creating your very first program in visual basic. It wasn't so hard now - was it?
Now you can go onto making more complex programs, or you can edit this one. I made some modifications to my program:
- I changed the background color
- I added some copyright info
- HINT: You do it using the properties window.
Participated in the
The Instructables Book Contest