WEBINAR:
On-Demand
Building the Right Environment to Support AI, Machine Learning and Deep Learning
Testing the Signature Control
You can now test the signature control. Back in Form1, double-click on it to reveal the code-behind. Code the following:
Public Class Form1
Private sig As New Signature
Private Sub Form1_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
With sig
.Location = New Point(3, 180)
.Size = New Size(233, 73)
.Enable = True
.InitSignature()
End With
Me.Controls.Add(sig)
Me.Refresh()
End Sub
End Class
Essentially, you are programmatically adding the signature control to the form. Press F5 to deploy it to an emulator (or a real device) and you should now be able to write on the signature control (see
Figure 6).

Figure 6. Testing the signature control on an emulator or a real device is now possible.
|
|

Figure 7. Populate Form1 with the various controls as shown here. |
Sending Signatures to Backend Server
Now that you have the signature control ready, it is time to code the logic to send the signature to a backend server. For this, you will use sockets communication.
Add a new class to the current project and name it Sync.vb. Populate it as follows:
Imports System.Net
Imports System.Net.Sockets
Public Class Sync
Const portNo As Integer = 3456
Private client As Socket
Public Sub PerformSync( _
ByVal HostIP As String, _
ByVal txtData As String)
Try
Dim RemoteAdd As System.Net.IPAddress = _
System.Net.IPAddress.Parse(HostIP)
Dim endPoint As New IPEndPoint(RemoteAdd, portNo)
client = New Socket(endPoint.AddressFamily, _
SocketType.Stream, ProtocolType.Tcp)
client.Connect(endPoint)
'---send a message to the server
Dim data As Byte() = _
System.Text.Encoding.ASCII.GetBytes(txtData & "*")
'---send the text---
client.Send(data)
MsgBox("Data sent!")
client.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
Back in the code-behind for Form1, add the following member variables:
Public Class Form1
Private sig As New Signature
'---use for synchronization---
Private sync As New Sync
'---IP address of the server---
Private ServerIP As String = "10.0.1.2"
'---the ID of the user---
Private ID As String = "1"
Author's Note: Substitute "10.0.1.2" with the IP address of your own server. More on this in the next section. |
Using the data-binding feature of Visual Studio 2005, bind the SQL Mobile database Northwind.sdf to a DataGrid control (see Figure 7) and add a Send menu item.
Author's note: You can refer to this screen cast to understand how to bind a table in a database to a DataGrid control. |
Code the Send menu button as follows:
Private Sub MenuItem1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MenuItem1.Click
'---send to the server---
Dim OrderID As String = _
OrdersDataGrid.Item( _
OrdersDataGrid.CurrentCell.RowNumber, 0). _
ToString()
sync.PerformSync(ServerIP, ID & "#" & OrderID & _
"#" & Now & "#" & sig.Signature)
'---clear the signature---
sig.InitSignature()
End Sub
Essentially, you are sending the following information to the server:
- ID of the person making the delivery
- Order ID
- Date and time of delivery
- Signature of the recipient