Visual Basic is a WYSIWYG design tool - What You See Is What You Get. You can simply draw shapes using the shape control and the line control. For example, a pumpkin can be drawn using a few circles and rectangles, like this:
To make a black circle, you need to draw a rectangle shape, then change some properties:
You might also want to change the border color.
You can draw a picture by using shapes and properties, but then the picture will just sit there when you run the program. If you want the picture to "do something", you need to write some programming commands.
The simplest way to execute some commands is by adding a button. When the user clicks the button, the picture changes.
You can add Command Buttons below the picture. Then double-click on a button and you can write the commands that will run when the button is pressed. In the picture above:
Notice that each command consists of:
This just makes the same changes that you could make in the Wysiwyg design environment, but it allows a user to make these changes while the program is running.
The program will be even more fun if things change automatically. For example, we can make an eye turn yellow, then black again, then yellow, then black again, etc. You could try these commands:
Shape3.FillColor = vbYellow
Shape3.FillColor
= vbBlack
Shape3.FillColor = vbYellow
Shape3.FillColor = vbBlack
This works, but it will execute VERY FAST and you won't see much. It's better to put a pause between the command.
Visual Basic doesn't really contain a pause command, so you will need to add a method - actually it's called a subroutine in Visual Basic, so it is enclose between sub and end sub commands. Then your program could look like this:
Private Sub Command4_Click()
Shape3.FillColor = vbYellow
wait 0.5
Shape3.FillColor = vbBlack
wait 0.5
Shape3.FillColor = vbYellow
wait 0.5
Shape3.FillColor = vbBlack
wait 0.5
Shape3.FillColor = vbYellow
wait 0.5
Shape3.FillColor = vbBlack
End Sub
Private Sub wait(sec)
t = Timer
While Timer < t + sec
DoEvents
Wend
End Sub