Drawing in Visual Basic

We are going to combine several of the techniques we have learned to create a larger program. Every time we click we will generate a random color and then draw a circle at the point we clicked. When that works, we will add a counter and print the number of the click on top of the circle. To make sure we can see the text we will create a second color that is different from the first color.

Since this combines several steps we will write them one at a time.

Close everything and start a new windows application named Dots.
Save AllSAVE ALL Often!! It only takes one click and it's worth it!
Do each step one by one. Don't look at the solution on the next page unless you are stuck.

  1. In the MouseClick event, declare laocal variables for red, green and blue.
  2. Give red, green, and blue random values from 0 to 255.
  3. Create a brush using the variables red, green, and blue for the color.
  4. Draw the circle with the center at the point clicked.
  5. Create a new brush color by subtracting each variable from 255. (This will give a contrasting color.)
  6. Declare a global variable Number with an initial value of 0.
  7. Increment Number by adding 1 to it in the MouseClick procedure.
  8. Draw Number using DrawString to print the new value of Number inside the circle.

NEXT: Numbered Dots Solution