I can't make the Pen smooth. If I adjusted the Size of the pen, it'll produce crack/gap. I don't have any idea to fix it. Check the image.
Here's the code.
Code:Public Class PaintFormDim PenWidth As Single = 1.0F Dim PenPoint As PenCode:Sub ReloadPen(ByVal PenWd As Single, ByVal CurColor As Color) PenPoint = New Pen(CurColor, PenWd) End SubCode:Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown If e.Button = Windows.Forms.MouseButtons.Left Then If drawing = False Then startLocation = e.Location drawing = True If MultiAngleRadioButton.Checked Then If TempLocation.X = -1 Then TempLocation = startLocation TempLocation2 = startLocation End If endLocation = e.Location g.DrawLine(PenPoint, TempLocation, endLocation) TempLocation = endLocation ElseIf TriangleRadioButton.Checked Then If TempLocation.X = -1 Then TempLocation = startLocation TempLocation2 = startLocation End If If NumberOfAngle <= 2 Then endLocation = e.Location g.DrawLine(PenPoint, TempLocation, endLocation) TempLocation = endLocation If NumberOfAngle = 2 Then g.DrawLine(PenPoint, TempLocation, TempLocation2) TempLocation = New Point(-1, -1) NumberOfAngle = 0 Else NumberOfAngle += 1 End If End If End If End If ElseIf e.Button = Windows.Forms.MouseButtons.Right Then If MultiAngleRadioButton.Checked Then If TempLocation.X <> -1 Then endLocation = e.Location g.DrawLine(PenPoint, TempLocation, TempLocation2) TempLocation = New Point(-1, -1) End If End If End If End SubCode:Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove If drawing = True Then If LineRadioButton.Checked Then g.DrawLine(PenPoint, startLocation.X, startLocation.Y, e.X, e.Y) startLocation = e.Location UpdateImage() ElseIf EraserRadioButton.Checked Then Dim p As New Pen(Color.White, PenWidth) g.DrawLine(p, startLocation.X, startLocation.Y, e.X, e.Y) startLocation = e.Location UpdateImage() End If End If End SubCode:Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp If drawing Then If RectangleRadioButton.Checked Then endLocation = e.Location Dim s As Point s.X = endLocation.X - startLocation.X If s.X < 0 Then startLocation.X = endLocation.X End If s.Y = endLocation.Y - startLocation.Y If s.Y < 0 Then startLocation.Y = endLocation.Y End If s.X = Math.Abs(s.X) s.Y = Math.Abs(s.Y) g.DrawRectangle(PenPoint, New Rectangle(startLocation, s)) ElseIf GradientRectAngleRadioButton.Checked Then endLocation = e.Location Dim s As Point If s.X < 0 Then startLocation.X = endLocation.X ElseIf s.X = 0 Then s.X = 1 End If s.Y = endLocation.Y - startLocation.Y If s.Y < 0 Then startLocation.Y = endLocation.Y ElseIf s.Y = 0 Then s.Y = 1 End If s.X = Math.Abs(s.X) s.Y = Math.Abs(s.Y) Dim b As Brush b = New Drawing2D.LinearGradientBrush(New Rectangle(startLocation, s), CurrentColor, CurrentColor2, Drawing2D.LinearGradientMode.BackwardDiagonal) g.FillRectangle(b, New Rectangle(startLocation, s)) ElseIf CircleRadioButton.Checked Then endLocation = e.Location Dim s As Point s.X = endLocation.X - startLocation.X If s.X < 0 Then startLocation.X = endLocation.X End If s.Y = endLocation.Y - startLocation.Y If s.Y < 0 Then startLocation.Y = endLocation.Y End If s.X = Math.Abs(s.X) s.Y = Math.Abs(s.Y) If s.X > s.Y Then s.Y = s.X Else s.X = s.Y End If g.DrawEllipse(PenPoint, New Rectangle(startLocation, s)) ElseIf ArcRadioButton.Checked Then endLocation = e.Location Dim s As Point s.X = endLocation.X - startLocation.X If s.X < 0 Then startLocation.X = endLocation.X End If s.Y = endLocation.Y - startLocation.Y If s.Y < 0 Then startLocation.Y = endLocation.Y End If s.X = Math.Abs(s.X) s.Y = Math.Abs(s.Y) If s.X > s.Y Then s.Y = s.X Else s.X = s.Y End If g.DrawArc(PenPoint, New Rectangle(startLocation, s), 0, -180) ElseIf ParallelepipedRadioButton.Checked Then endLocation = e.Location Dim s As Point s.X = endLocation.X - startLocation.X If s.X < 0 Then Dim tmp As Integer = startLocation.X startLocation.X = endLocation.X endLocation.X = tmp End If s.Y = endLocation.Y - startLocation.Y If s.Y < 0 Then Dim tmp As Integer = startLocation.Y startLocation.Y = endLocation.Y endLocation.Y = tmp End If s.X = Math.Abs(s.X) s.Y = Math.Abs(s.Y) Dim p(3) As Point p(0) = New Point(startLocation.X + s.X / 5, startLocation.Y) p(1) = New Point(startLocation.X + s.X, startLocation.Y) p(2) = New Point(endLocation.X - s.X / 5, endLocation.Y) p(3) = New Point(endLocation.X - s.X, endLocation.Y) g.DrawPolygon(PenPoint, p) ElseIf FillRadioButton.Checked Then FillRegion(e.X, e.Y, CurrentColor) ElseIf TextRadioButton.Checked Then Dim txt As String = Me.TextDrawTextBox.Text g.DrawString(txt, CurrentFont, New Drawing2D.HatchBrush(Drawing2D.HatchStyle.BackwardDiagonal, CurrentColor), e.X, e.Y) End If End If drawing = False UpdateImage() End SubCode:Private Sub PaintForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load g = Graphics.FromImage(LastImage) g.Clear(Color.White) UpdateImage() ReloadPen(PenWidth, CurrentColor) End Sub



Reply With Quote

