Drawing lines with dots leaves spaces if mouse moves too fast

  • Thread starter Thread starter Manuel Daponte
  • Start date Start date
M

Manuel Daponte

I found this code in this newsgroup and used it, but the lines drawn
are composed of point too separated when the mouse moves at medium or
fast speed. How can I fix it?

Thanks in advance !!!

Dim bTracking As Boolean
Dim blackPen As Pen
Dim g As Graphics

Private Sub frmFirma_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
blackPen = New Pen(Color.Black, 2)
blackPen.LineJoin = Drawing2D.LineJoin.Round
g = PictureBox1.CreateGraphics()
End Sub

Private Sub AddPoint(ByVal e As
System.Windows.Forms.MouseEventArgs)
g.DrawLine(blackPen, e.X, e.Y, e.X + 1, e.Y + 1)
End Sub

Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e
As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
bTracking = True
AddPoint(e)
End Sub

Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e
As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If bTracking Then
AddPoint(e)
End If
End Sub

Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
If bTracking Then
AddPoint(e)
bTracking = False
End If
End Sub

Protected Overrides Sub Finalize()
g.Dispose()
MyBase.Finalize()
End Sub
 
Draw lines instead of points.

Actually, I'm drawing small lines (2 points)...

The thing is that this will be used in a picture box, in an tabletPC app, to pick a signature. Do you have a better chunk of code
for that?

Thanks in advance for you help !!!
 
* "Manuel Daponte said:
Actually, I'm drawing small lines (2 points)...

The thing is that this will be used in a picture box, in an tabletPC app, to pick a signature. Do you have a better chunk of code
for that?

I think that's already a good solution. There may be better solutions
using interpolation to make everything look more smooth, but I think
that's too much effort...
 
Manuel Daponte said:
Actually, I'm drawing small lines (2 points)...

The thing is that this will be used in a picture box, in an tabletPC app, to pick a signature. Do you have a better chunk of code
for that?

Thanks in advance for you help !!!


Here is a quick example of drawing on the form. (Drawing on the form
offers no persistance) Paste the code below in a new project, AFTER
the designer code section:

HTH
LFS


Private grx As Graphics
Private mouse As Point
Private ink As Pen = New Pen(Color.MidnightBlue, 3)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
grx = Me.CreateGraphics
grx.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
Dim pos As Point = New Point(e.X, e.Y)
If e.Button = MouseButtons.Left Then
grx.DrawLine(ink, mouse, pos)
mouse = pos
End If
End Sub

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
mouse = New Point(e.X, e.Y)
End Sub
 
It's perfect !!! Thanks !!!

--
Manuel A. Daponte Santiago
--------------------------
DBA Municipio de Guaynabo


Manuel Daponte said:
Actually, I'm drawing small lines (2 points)...

The thing is that this will be used in a picture box, in an tabletPC app, to pick a signature. Do you have a better chunk of code
for that?

Thanks in advance for you help !!!


Here is a quick example of drawing on the form. (Drawing on the form
offers no persistance) Paste the code below in a new project, AFTER
the designer code section:

HTH
LFS


Private grx As Graphics
Private mouse As Point
Private ink As Pen = New Pen(Color.MidnightBlue, 3)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
grx = Me.CreateGraphics
grx.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
Dim pos As Point = New Point(e.X, e.Y)
If e.Button = MouseButtons.Left Then
grx.DrawLine(ink, mouse, pos)
mouse = pos
End If
End Sub

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
mouse = New Point(e.X, e.Y)
End Sub
 
Back
Top