Simple Drawing Package

Learn to make a Simple Drawing Package using Visual Basic 6 with this Tutorial that Celebrates the CESPage 25th Anniversary

Well if you did the Drawing tutorial this is even better, which will introduce you to the ComboBox control along with using the PictureBox and Command Button controls.

Step 1

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

Step 2

A Blank Form named Form1 should then appear
Blank Form

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
Form with Picture Box

Step 5

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

Step 6

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

Step 7

Draw Two Combo Boxes on the Form
Form with Two Combo Boxes

Step 8

Change the Style Property of both Combo Boxes of 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 Command Button to Quit
Form with Three Combo Boxes and Command Button

Step 11

Double Click on the Command Button labelled Quit or Command1 and type in the Command1_Click() Sub:


Unload Me
                                    

Step 12

Double Click on the Form of 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 of Picture1 and type in the Picture1_MouseDown() Sub:


Picture1.CurrentX = X
Picture1.CurrentY = Y
                                    

Step 14

Double Click on the PictureBox of 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
This should Start the application
Simple Drawing Package 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.
Simple Drawing Package Drawn

Step 17

You can draw in any of the widths and colours available by selecting the appropriate option from the two Combo Boxes. To Exit the application, Click on Quit or End / Stop
End / Stop

Great you have just created an improved Simple Drawing Package! Try changing the program so that other Draw Widths are available (add more values to the With Combo1 List!) Plus add more colours by adding the new names e.g. Yellow and then in the MouseMove Sub of the Picture Box 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 Simple Drawing Package!