Exercise 9 :: The Paint program project

This exercise is a very large and involved one. It is about as much work as the previous text editor, but we will not be giving so much guidance. An example program has been created and you can use that for "inspiration". The full project is available here (you may ignore subdirectories) and the executable can be found here here. For this project you are expected to take a planned software development approach. We describe this in more detail a little later in this exercise. In short, the suggested method for this exercise is to go through it in the following order.
  1. Read about graphics programming
  2. Look at the example program
  3. Plan your program using the tips we provide
  4. Start programming
  5. Use the example project (you may ignore subdirectories) for any parts where you are getting stuck (only as a last resort!!!)
  6. Test your program

Graphics programming in VB

Programming graphics in VB is quite simple. The picture control has got special methods to allow you to add lines, rectangles and circles to it. The first step in adding graphics capabilities to your program is to add a picture control. Make it a good size as it will act as the canvas for all of your drawing. From this point on I will assume your picture control is called picCanvas. Once you have this control, the following code will add a line going from the coordinate (startPointX, startPointY) to coordinate (endPointX, endPointY). Note that in VB (as in many other graphics systems) x coordinates are low at the top (high at the bottom) and y coordinates are low to the left (and high to the right).
picCanvas.Line (startPointX, startPointY)-(endPointX, endPointY)
This code will add a rectangle
picCanvas.Line (startPointX, startPointY)-(endPointX, endPointY), , B
Notice that the only difference it the presence of the empty third parameter and the fourth parameter specifying B for box. The third parameter (which in this case is empty) can be used to specify the fill colour if desired.

This code will add a circle

picCanvas.Circle (centerPointX, centerPointY), radius
The picture object also has the method Cls which will clear anything drawn in the window.

Task 1 :: Designing your project

Before programming, it is always a good idea to think out your project in full. The more work you do before you start programming the less work you will have to do overall. By planning your project carefully, you can avoid making mistakes once you start coding. Mistakes are much harder to fix once you have committed them to code.

project description
We require a painting program. It should be able to draw lines, circles and rectangles to a region of the screen. It should also be able to clear the screen (new image), save images and open previously saved images. An example of the required functionality can be found in this program.

How to plan


Task 2 :: Programming and testing

Once you have a good design for your program, coding it should be easy. Once the coding is completed, you have to carefully test it for bugs.

  1. Perform all the coding for your paint program. The entire workshop to this point has been about programming, so we wont go over it again here.
  2. Test your paint program. Here are some tips
    • Start with the simple tests. Try drawing a line, then the other shapes.
    • Test your new image functionality
    • Test that you can save a file. To see that it has been saved correctly, view the saved file in a text editor
    • Test opening files.
    • Your final step in testing will be the longest. You need to test all the hard cases. Try to think of things that a user might do with your program that will show up a bug. Perhaps try opening or saving an empty file, or choose a strange combination of keystrokes (i.e. not what was expected).
  3. Now that you have finished, you can make the executable ("File->Make exe").

Help is at hand

If you are unable to create the paint program as you would like, or you are just curious to see how the example was programmed, you can have a look at the example project (you may ignore subdirectories).

EXTRAS ->


Matthew Roberts, Macquarie University 2002