Basic Paint App using VB2010
Posted: Tue Jan 25, 2011 9:48 pm
This is my first VB 2010 app I made, it is a basic painter based on the Windows operating system app Paint.
Version 1.
Source Code:
Version 1.
Source Code:
Code: Select all
Public Class PaintForm
Private shouldPaint As Boolean = False ' determines whether to paint
Dim PaintColor As Color
'***************************************************
' Load all our Radiobuttons and Set Radiobutton1.
'***************************************************
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.RadioButton1.Tag = Color.Black
Me.RadioButton2.Tag = Color.Yellow
Me.RadioButton3.Tag = Color.Green
Me.RadioButton4.Tag = Color.Purple
Me.RadioButton5.Tag = Color.Pink
Me.RadioButton6.Tag = Color.Brown
Me.RadioButton7.Tag = Color.Cyan
Me.RadioButton8.Tag = Color.Red
Me.RadioButton9.Tag = Color.Blue
Me.RadioButton10.Tag = Color.Orange
Me.RadioButton11.Tag = Color.White
Me.RadioButton1.Checked = True
End Sub
'***************************************************
' Check our Mouse button to paint on screen = True
'***************************************************
Private Sub Panel1_MouseDown(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles Panel3.MouseDown
shouldPaint = True
End Sub
'***************************************************
' Check our Mouse button to paint on screen = False
'***************************************************
Private Sub Panel1_MouseUp(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles Panel3.MouseUp
shouldPaint = False
End Sub
'***************************************************
' Draws on Panel3 with mouse clicked.
'***************************************************
Private Sub Panel1_MouseMove(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles Panel3.MouseMove, RadioButton1.MouseMove, RadioButton1.MouseClick
If (shouldPaint) Then
Using g As Graphics = Panel3.CreateGraphics()
g.FillEllipse(New SolidBrush(PaintColor), e.X, e.Y, 4, 4)
g.Dispose()
End Using
End If
End Sub '
'***************************************************
' Selects which colour by check/change of Radiobuttons.
'***************************************************
Private Sub RadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, RadioButton3.CheckedChanged, RadioButton4.CheckedChanged, RadioButton5.CheckedChanged, RadioButton6.CheckedChanged, RadioButton7.CheckedChanged, RadioButton8.CheckedChanged, RadioButton9.CheckedChanged, RadioButton10.CheckedChanged, RadioButton11.CheckedChanged
If CType(sender, RadioButton).Checked = True Then
PaintColor = CType(CType(sender, RadioButton).Tag, Color)
End If
End Sub
'***************************************************
' Clears Panel3 when the Clear button is pressed.
'***************************************************
Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
Dim a As Graphics = Panel3.CreateGraphics()
a.Clear(Color.White)
End Sub
End Class