Imports System.Drawing.Graphics
Public Class Form1
Inherits System.Windows.Forms.Form
Dim x1, y1, x2, y2 As Integer
Dim red, black, blue, green, orange As Color
Dim x, y, w, h As Integer
Dim rectangle, freehand As Graphics
Dim line As Graphics
Dim wide, n As Integer
Dim myPen As Pen
#Region " Windows Form Designer generated code "
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
'prevents the user from making the form smaller than its original size
If Me.Width < 368 Then Me.Width = 368
If Me.Height < 312 Then Me.Height = 312
End Sub
Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
Picbox.Image = Nothing 'clears picture box
End Sub
Private Sub Picbox_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Picbox.MouseDown
'gets the co-ordinates of when the mouse button is pressed
x1 = Location.X
y1 = Location.Y
End Sub
Private Sub Picbox_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Picbox.MouseUp
'gets the co-ordinates of when the mouse button is released
x2 = Location.X
y2 = Location.Y
End Sub
Private Sub Btndraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btndraw.Click
Dim mygraphics As Graphics
Dim mycoordinates As Integer
mygraphics = Picbox.CreateGraphics
Dim mywidth As Integer
Dim mycolor As Color
Dim myrectangle As Rectangle
Dim mytool As Graphics
Dim myline As Graphics
' gets the user selected color
If CmbColor.Text.Equals(black) Then
mycolor = black
ElseIf CmbColor.Text.Equals(red) Then
mycolor = red
ElseIf CmbColor.Text.Equals(blue) Then
mycolor = blue
ElseIf CmbColor.Text.Equals(green) Then
mycolor = green
ElseIf CmbColor.Text.Equals(orange) Then
mycolor = orange
End If
' gets the user selected width
If CmbWidth.Text = CStr(1) Then
mywidth = 1
ElseIf CmbWidth.Text = CStr(2) Then
mywidth = 2
ElseIf CmbWidth.Text = CStr(3) Then
mywidth = 3
ElseIf CmbWidth.Text = CStr(4) Then
mywidth = 4
ElseIf CmbWidth.Text = CStr(5) Then
mywidth = 5
End If
'gets the user selected drawing tool
If CmbTool.Text Is line Then
mytool = line
ElseIf CmbTool.Text Is rectangle Then
mytool = rectangle
ElseIf CmbTool.Text Is freehand Then
mytool = freehand
End If
myPen = New Pen(mycolor, mywidth)
' mytool = (myline)
myPen = New Pen(Color:=Color.CadetBlue, Width:=4)
mygraphics.DrawLine(Pen:=myPen, x1:=35, y1:=35, x2:=300, y2:=400)
myrectangle = New Rectangle(x:=30, y:=30, Width:=80, Height:=160)
mygraphics.DrawRectangle(Pen:=myPen, rect:=myrectangle)
End Sub
End Class