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
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 & "|")
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:
Private Sub btnClear_MouseLeftButtonUp( _
ByVal sender As Object, _
ByVal e As System.Windows.Input.MouseEventArgs) _
_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
txtStatus.Text = "Signature cleared!"
Here, you are simply iteratively removing all the lines in the canvas.