Below is all of my code. It works, except the PenWidth. I can't figure out what I'm doing wrong.
VB.NET:
Option Strict On
Public Class Form1
Dim MyPen As New Pen(Color.Black)
Dim PenColor As Color
Dim IsThePenDown As Boolean
Dim MouseDownPoint As Point
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
picBoxOutput.BackColor = Color.White
cmbSelectColor.Items.Add("Red")
cmbSelectColor.Items.Add("Orange")
cmbSelectColor.Items.Add("Yellow")
cmbSelectColor.Items.Add("Green")
cmbSelectColor.Items.Add("Blue")
cmbSelectColor.Items.Add("Indigo")
cmbSelectColor.Items.Add("Violet")
cmbSelectColor.Items.Add("Brown")
cmbSelectColor.Items.Add("White")
cmbSelectColor.Items.Add("Gray")
cmbSelectColor.Items.Add("Black")
cmbSelectColor.Items.Add("Pink")
cmbSelectColor.Items.Add("Magenta")
cmbSelectColor.Items.Add("Cyan")
End Sub
Private Sub ClearThePictureToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearThePictureToolStripMenuItem.Click
'Call the ClearPic SUB.>>
Call ClearPic()
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'Call the ClearPic SUB.>>
Call ClearPic()
End Sub
Private Sub ClearPic()
'Clear the PictureBox to WHITE.>>
picBoxOutput.CreateGraphics.Clear(Color.White)
End Sub
Private Sub SetpenColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SetpenColorToolStripMenuItem.Click
'Show the ComboBox to select a color.>>
cmbSelectColor.Show()
End Sub
Private Sub SetPenwidthToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SetPenwidthToolStripMenuItem.Click
'Show the Panel to Set the Pen Width.>>
pnlSetPenWidth.Show()
End Sub
Private Sub cmbSelectColor_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSelectColor.SelectedIndexChanged
'Set the pen color to the selected color.>>
MyPen.Color = Color.FromName(cmbSelectColor.SelectedItem.ToString)
End Sub
Private Sub rdoBtnWidth_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoBtnWidth1.CheckedChanged, rdoBtnWidth2.CheckedChanged, rdoBtnWidth3.CheckedChanged, rdoBtnWidth4.CheckedChanged
'Used to hold the Pen width.>>
Dim PenWidth As Integer
'Usedto hold which radioBtton was clicked on.>>
Dim WhichRadioButton As RadioButton
If TypeOf sender Is RadioButton Then
WhichRadioButton = CType(sender, RadioButton)
'Pass the number of the control to the PenWidth variable.>>
Integer.TryParse(WhichRadioButton.Name.Substring(5), PenWidth)
'Then set the Pen Width.>>
MyPen.Width = PenWidth
End If
End Sub
Private Sub picBoxOutput_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picBoxOutput.MouseDown
'If the left mouse button is down the set IsThePenDown to TRUE
If e.Button = Windows.Forms.MouseButtons.Left Then
IsThePenDown = True
'Set the Point to start drawing from.>>
MouseDownPoint = New Point(e.X, e.Y)
End If
End Sub
Private Sub picBoxOutput_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picBoxOutput.MouseUp
'Set to FALSE on the MouseUp event.>>
IsThePenDown = False
End Sub
Private Sub picBoxOutput_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picBoxOutput.MouseMove
'A STATIC variable holds or remebers the previous value.>>
Static LastPoint As New Point
If IsThePenDown = True Then
'Draw a line from the LastPoint.>>
picBoxOutput.CreateGraphics.DrawLine(MyPen, LastPoint.X, LastPoint.Y, e.X, e.Y)
End If
'Set the LastPoint to the previous point.>>
LastPoint = New Point(e.X, e.Y)
End Sub
Private Sub ToolStripComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripComboBox1.SelectedIndexChanged
MyPen.Color = Color.FromName(ToolStripComboBox1.SelectedItem.ToString)
OptionsToolStripMenuItem.HideDropDown()
cmbSelectColor.Text = ToolStripComboBox1.SelectedItem.ToString
End Sub
Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
MyPen.Width = CSng(ToolStripMenuItem2.Text)
End Sub
Private Sub ToolStripMenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem3.Click
MyPen.Width = CSng(ToolStripMenuItem3.Text)
End Sub
End Class