Saving the Signature
Now that you can sign on the canvas, it's time to save the signature to somewhere. But first, add the code shown in
Listing 3 to
Page.xaml.
Page.xaml should now look like the example shown in Figure 3 (you can view this in Expression Blend 2).
 | |
| Figure 3. Page.xaml: The page with three buttons and a TextBlock control. |
In Page.xaml.vb, define the GetSignatureLines() function so that the coordinates of the signature can be serialized as a string:
'---returns the signature as a series of lines---
Private Function GetSignatureLines() As String
Dim sb As New System.Text.StringBuilder
'---for each line---
For i As Integer = 0 To _lines.Count - 1
'---for each point---
For Each pt As Point In _lines(i)
sb.Append(pt.X & "," & pt.Y & "|")
Next
sb.Append(vbLf)
Next
Return sb.ToString
End Function
Define the
DrawSignature() subroutine so that the signature can be reproduced from the collection of lines, as shown in
Listing 4.
This subroutine is needed so that later on you can reproduce a saved signature when you retrieve it from the web service.
Code the MouseLeftButtonDown event handler for the Clear button so that the signature can be cleared from the drawing pad:
'---Clear button---
Private Sub btnClear_MouseLeftButtonUp( _
ByVal sender As Object, _
ByVal e As System.Windows.Input.MouseEventArgs) _
Handles btnClear.MouseLeftButtonUp
_lines = New List(Of Object)
_points = New List(Of Point)
'---iteratively clear all the signature lines---
For i As Integer = 0 To SigPad.Children.Count - 2
SigPad.Children.RemoveAt(1)
Next
txtStatus.Text = "Signature cleared!"
End Sub
Here, you are simply iteratively removing all the lines in the canvas.