M
Mobile Boy 36
Dear All,
I'm making a signaturecontrol class. It is working but very slow.
I override the mousemove event and the onpaint event from the base class
System.windows.Forms.PictureBox.
In the onmouse event I use Me.Invalidate to raise the onpaint event.
What am I doing wrong? Why is it so slow?
Best regards,
MobileBoy
Imports System.Drawing
Imports System.Windows.Forms
Public Class Controlleken
Inherits System.windows.Forms.PictureBox
Private Punten As New ArrayList
Private laatstelocatie As New Point(-1, -1)
Private md As Boolean = False
Private g As Graphics
Private AantalMouseMoves As Integer = 0
Private b As New System.Drawing.SolidBrush(System.Drawing.Color.Blue)
Private TekenString As Boolean = True
Protected Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
' Create a local version of the graphics object for the PictureBox.
'Dim g As Graphics = pe.Graphics
g = pe.Graphics
MyBase.OnPaint(pe)
' Draw a string on the PictureBox.
If TekenString Then
g.DrawString("This is a diagonal line drawn on the control", New
System.Drawing.Font("Arial", 10, FontStyle.Regular), b, 30, 30)
TekenString = False
End If
' Draw a line in the PictureBox.
' g.DrawLine(System.Drawing.Pens.Red, pictureBox1.Left,
pictureBox1.Top, pictureBox1.Right, pictureBox1.Bottom)
'teken de punten uit de array
teken()
End Sub
Private Sub teken()
Dim pen As New Pen(System.Drawing.Color.Blue)
Dim lp As Point
If Punten.Count > 0 Then
lp = Punten(0)
For Each p As Point In Punten
g.DrawLine(pen, lp.X, lp.Y, p.X, p.Y)
lp = p
Next
End If
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
MyBase.OnMouseMove(e)
If md Then
AantalMouseMoves = AantalMouseMoves Mod 2 + 1
Punten.Add(New Point(e.X, e.Y))
If AantalMouseMoves = 1 Then
'MyBase.Invalidate()
Me.Invalidate()
End If
End If
End Sub
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
MyBase.OnMouseDown(e)
md = True
End Sub
Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
MyBase.OnMouseUp(e)
md = False
'Me.Refresh()
End Sub
End Class
I'm making a signaturecontrol class. It is working but very slow.
I override the mousemove event and the onpaint event from the base class
System.windows.Forms.PictureBox.
In the onmouse event I use Me.Invalidate to raise the onpaint event.
What am I doing wrong? Why is it so slow?
Best regards,
MobileBoy
Imports System.Drawing
Imports System.Windows.Forms
Public Class Controlleken
Inherits System.windows.Forms.PictureBox
Private Punten As New ArrayList
Private laatstelocatie As New Point(-1, -1)
Private md As Boolean = False
Private g As Graphics
Private AantalMouseMoves As Integer = 0
Private b As New System.Drawing.SolidBrush(System.Drawing.Color.Blue)
Private TekenString As Boolean = True
Protected Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
' Create a local version of the graphics object for the PictureBox.
'Dim g As Graphics = pe.Graphics
g = pe.Graphics
MyBase.OnPaint(pe)
' Draw a string on the PictureBox.
If TekenString Then
g.DrawString("This is a diagonal line drawn on the control", New
System.Drawing.Font("Arial", 10, FontStyle.Regular), b, 30, 30)
TekenString = False
End If
' Draw a line in the PictureBox.
' g.DrawLine(System.Drawing.Pens.Red, pictureBox1.Left,
pictureBox1.Top, pictureBox1.Right, pictureBox1.Bottom)
'teken de punten uit de array
teken()
End Sub
Private Sub teken()
Dim pen As New Pen(System.Drawing.Color.Blue)
Dim lp As Point
If Punten.Count > 0 Then
lp = Punten(0)
For Each p As Point In Punten
g.DrawLine(pen, lp.X, lp.Y, p.X, p.Y)
lp = p
Next
End If
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
MyBase.OnMouseMove(e)
If md Then
AantalMouseMoves = AantalMouseMoves Mod 2 + 1
Punten.Add(New Point(e.X, e.Y))
If AantalMouseMoves = 1 Then
'MyBase.Invalidate()
Me.Invalidate()
End If
End If
End Sub
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
MyBase.OnMouseDown(e)
md = True
End Sub
Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
MyBase.OnMouseUp(e)
md = False
'Me.Refresh()
End Sub
End Class