Simple Drawing Package

Well if you did the Drawing Tutorial this is even better, which will introduce you to the ComboBox and PictureBox Controls plus a little about Command Buttons.

Printer Friendly Download Tutorial (51.6KB) Download Source Code (7KB)

Step 1

Load Microsoft Visual Basic, then select Standard EXE Project if VB5/6, click on the option then click Open, see below:

New Project

Step 2

A Blank Form named Form1 should then appear, see below:

Form 1

Step 3

Then from the Visual Basic Components Menu Select the Picture Box Control:

Picture Box Control

Step 4

Draw a Picture Box on the Form as shown below:

Form with Picture Box

Step 5

Then goto the Properties Box and change AutoRedraw to True, see below:

Picture Box Properties

Step 6

Then from the Visual Basic Components Menu Select the ComboBox Control:

ComboBox Control

Step 7

Draw Two Combo Boxes on the Form as shown below:

Form with PictureBox and Two Combo Boxes

Step 8

Change the Style Property of both Combo Boxes (Combo1 and Combo2) to 2- Dropdown List.

Step 9

Then from the Visual Basic Components Menu Select the Command Button Control:

Command Button Control

Step 10

Draw a Command Button on the Form, and change the Caption Property of the Button to Quit, as shown below:

Form with Picture Box, Two Combo Boxes and a Command Button

Step 11

Double Click on the Button Labeled Quit (Command1) and type in the Command1_Click() Sub:

Unload Me

Step 12

Double Click on the Form (Form1) and type in the Form_Load() Sub:

With Combo1
  .AddItem 1
  .AddItem 2
  .AddItem 4
  .AddItem 8
  .AddItem 16
  .AddItem 32
  .AddItem 64
End With
Combo1.ListIndex = 0
With Combo2
  .AddItem "Black"
  .AddItem "Red"
  .AddItem "Green"
  .AddItem "Blue"
  .AddItem "White"
End With
Combo2.ListIndex = 0 

Step 13

Double Click on the PictureBox (Picture1) and type in the Picture1_MouseDown() Sub:

Picture1.CurrentX = X
Picture1.CurrentY = Y

Step 14

Double Click on the PictureBox (Picture1) and type in the Picture1_MouseMove() Sub:

Dim Colour As String
If Button = 1 Then
  Picture1.DrawWidth = Combo1.Text
  If Combo2.Text = "Black" Then Colour = vbBlack
  If Combo2.Text = "Red" Then Colour = vbRed
  If Combo2.Text = "Green" Then Colour = vbGreen
  If Combo2.Text = "Blue" Then Colour = vbBlue
  If Combo2.Text = "White" Then Colour = vbWhite
  Picture1.Line (Picture1.CurrentX, Picture1.CurrentY)-(X, Y), Colour
End If 

Step 15

Save the Project (for example prjDrawingPackage) into a vacant folder as you have finished the application. Click on Start / Run Start / Run or Press F5 and the below will appear:

Application Running

Step 16

Change the Value in the Left Combo Box to 8 and the Text in the Right Combo Box to Blue, and draw something, see below:

Drawing with Drawing Package

Step 17

You can draw in any of the widths and colours available by selecting the appropriate option from the two combo boxes. To Quit the Application, Click on Quit.

Great you have just created an improved Drawing Package! Try changing the program so that other Draw Widths are available (add more values to the Combo1 With Combo1 List!) Plus add more colours by adding the new names e.g. Yellow and then in the MouseMove Sub of the PictureBox add a conversion routine e.g. If Combo2.Text="Yellow" then Colour=vbYellow. Try changing other parts of the code and extending it, you can learn a lot from this drawing package!

Copyright Comentsys © 1997 - 2009, All rights reserved. About | Contact | Link to Page
Valid XHTML 1.1! Valid CSS Level Double-A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0 This website is ICRA rated