|
-
May 10th, 2012, 01:07 PM
#1
Thread Starter
New Member
Paint application | Multiple pen strokes with different colors
I am new to VB. I am trying to make a 'paint' type application, where you can choose a pen color, draw lines, and if you choose to change the color, the original lines will remain unchanged and you can continue your drawing with a different color.
Below is the code that I have so far. What happens is when you start to draw, and then change the pen color, every line that has been created will change color. I want to make it so that choosing a new color will not effect the previous lines that have been drawn.
I tried to make mousePath a dynamic array to maybe store each line as an additional object, but I kept getting exceptions.
Please advise...
Public Class Form1
Public myColor As Color
Dim mousePath As New System.Drawing.Drawing2D.GraphicsPath
Dim i As Integer
Public Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
If e.Button = MouseButtons.Left Then
mousePath.StartFigure()
End If
End Sub
Public Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = MouseButtons.Left Then
Try
mousePath.AddLine(e.X, e.Y, e.X, e.Y)
Catch
End Try
End If
PictureBox1.Invalidate()
End Sub
Public Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
If i = 0 Then
myColor = Color.Black
i = i + 1
End If
Dim CurrentPen = New Pen(myColor, 2)
Try
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
e.Graphics.DrawPath(CurrentPen, mousePath)
Catch ex As Exception
End Try
End Sub
Private Sub ShowColo*******tripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowColo*******tripMenuItem.Click
If i > 0 Then
If (ColorDialog1.ShowDialog() = DialogResult.OK) Then
myColor = ColorDialog1.Color
i = i + 1
End If
End If
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|