signature - very slow...


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
 
Ad

Advertisements

A

Andreas Wolff

Am Fri, 29 Oct 2004 13:03:47 +0200 schrieb 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?
[..]

Hi,
i found this in the morning:

Pocket PC Signature Application Sample
http://msdn.microsoft.com/mobility/...rary/en-us/dnnetcomp/html/ppcsignatureapp.asp

At the end of this document, a similar approach is described..

Best regards
Andreas
 
S

Steven Licciardi

I do something very similar and found that cycling through all your points
on every invalidate is the problem, especially so if you are invalidating
every mousemove event (seems to take some time to actually draw all those
lines). In order to resolve this I create a bitmap and draw to the bitmap,
on each mousemove event I simply draw the ADDITIONAL lines to the bitmap,
then in each OnPaint just draw the whole bitmap to the Picturebox graphic
(g.DrawImage...... etc...), this way you are not cycling through all your
points every time you invalidate, just the new ones, this seems to work very
well here.

HTH,

Steven
 
M

Mobile Boy 36

Thank you Andreas, I will take a look at it.
Does someone have specific information for my my problem?

Andreas Wolff said:
Am Fri, 29 Oct 2004 13:03:47 +0200 schrieb 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?
[..]

Hi,
i found this in the morning:

Pocket PC Signature Application Sample
http://msdn.microsoft.com/mobility/...rary/en-us/dnnetcomp/html/ppcsignatureapp.asp

At the end of this document, a similar approach is described..

Best regards
Andreas
 
R

Rob Tiffany, eMVP

Signature Capture Control 3.0 from Hood Canal Mobility is only $9.95 at
Pocket Gear and Handango.

Rob Tiffany
 
Ad

Advertisements

G

Guest

Check out the OpenNETCF.Windows.Forms.Signature control part of the OpenNETCF
SDF. (www.opennetcf.org) You can propbably get some ideas on how to
implement your signature control or just use the OpenNETCF control.

---
Mark Arteaga
..NET Compact Framework MVP
www.neotericsdc.com

Mobile Boy 36 said:
Thank you Andreas, I will take a look at it.
Does someone have specific information for my my problem?

Andreas Wolff said:
Am Fri, 29 Oct 2004 13:03:47 +0200 schrieb 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?
[..]

Hi,
i found this in the morning:

Pocket PC Signature Application Sample
http://msdn.microsoft.com/mobility/...rary/en-us/dnnetcomp/html/ppcsignatureapp.asp

At the end of this document, a similar approach is described..

Best regards
Andreas
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top