Drawing in Visual Basic

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:

img3.gif

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.

Changing Properties While Running

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.

img4.gif

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.

Automation

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:

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:

Practice

  1. Use shapes and properties to make a halloween picture - for example a pumpkin and some candy bars.
  2. Add a few buttons that make colors change or make pieces appear and disappear.
  3. Using wait commands, make some animations where things disappear, reappear and change colors in order when a button is pressed.
  4. Make a [Reset] button that changes everything back to it's original appearance.  
  5. Make a Trick-Or-Treat-Time button.  When this is clicked, the background turns black and something lights up - showing that it is night-time.
    Then the words "Trick-Or-Treat" appear somewhere.  These words should be invisible when the program starts.