Hello,
Im attempting to write a signature capture control that will store and reload an image. If its not too much trouble, could someone please take a look at my SaveSigAsImage and OpenSigImage routine and hint on why they do not work.
Thank you.
Im attempting to write a signature capture control that will store and reload an image. If its not too much trouble, could someone please take a look at my SaveSigAsImage and OpenSigImage routine and hint on why they do not work.
Thank you.
Code:
Public Class Signature
Inherits System.Windows.Forms.UserControl
Public OldX As Integer
Public OldY As Integer
Public pen As New Drawing.Pen(System.Drawing.Color.Black, 1)
Public bolStartSign As Boolean
Public bolMouseUp As Boolean = True
Dim aWidth As Integer = 500
Dim aHeight As Integer = 500
Dim aBgColor As Drawing.Color = Drawing.Color.White
Dim b As New Drawing.Bitmap(aWidth, aHeight)
Dim g As Drawing.Graphics = Drawing.Graphics.FromImage(b)
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
This call is required by the Windows Form Designer.
InitializeComponent()
Add any initialization after the InitializeComponent() call
End Sub
UserControl overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
NOTE: The following procedure is required by the Windows Form Designer
It can be modified using the Windows Form Designer.
Do not modify it using the code editor.
Friend WithEvents picSig As System.Windows.Forms.PictureBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.picSig = New System.Windows.Forms.PictureBox
Me.SuspendLayout()
picSig
Me.picSig.BackColor = System.Drawing.Color.White
Me.picSig.Location = New System.Drawing.Point(16, 8)
Me.picSig.Name = "picSig"
Me.picSig.Size = New System.Drawing.Size(304, 192)
Me.picSig.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
Me.picSig.TabIndex = 0
Me.picSig.TabStop = False
Signature
Me.Controls.Add(Me.picSig)
Me.Name = "Signature"
Me.Size = New System.Drawing.Size(416, 304)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
picSig.Top = 0
picSig.Left = 0
picSig.Width = Me.Width
picSig.Height = Me.Height
g.Clear(aBgColor)
g.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
End Sub
Private Sub Signature_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
picSig.Width = Me.Width
picSig.Height = Me.Height
End Sub
Private Sub picSig_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picSig.MouseMove
If Not bolMouseUp Then need to show the image the sametime creating it
picSig.CreateGraphics.DrawLine(pen, OldX, OldY, e.X, e.Y)
g.DrawLine(pen, OldX, OldY, e.X, e.Y)
OldX = e.X
OldY = e.Y
End If
End Sub
Private Sub picSig_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picSig.MouseUp
bolMouseUp = True
End Sub
Private Sub picSig_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picSig.MouseDown
bolMouseUp = False
OldX = e.X
OldY = e.Y
End Sub
Public Sub SaveSigAsImage(ByVal Path As String)
Dim i As Image = picSig.Image
i.Save(Path, Drawing.Imaging.ImageFormat.Bmp)
End Sub
Public Sub OpenSigImage(ByVal Path As String)
Dim img As Image = Image.FromFile(Path)
picSig.Image = img
b = img
End Sub
Public Sub ClearSignature()
picSig.Refresh()
End Sub
Private Sub picSig_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles picSig.Paint
e.Graphics.DrawImage(b, 0, 0)
End Sub
End Class