Adding a Form
Now that you have a simple plug-in ready to go, all you need is something to attach it to. In a very simple version, this could be a form. When that form instantiates, create a RealTimeStylus object and point it to the UI control you want to collect pen information on (in this example the entire window, but it could be an individual control, such as a textbox or a panel). Then, instantiate the plug-in object and add it to the Real Time Stylus' SyncPluginCollection. The following snippet shows how this can be done in VB.NET:
Private rts As RealTimeStylus
Public Sub New()
'This call is req. by the Win Form Designer.
'We create the stylus
Me.rts = New RealTimeStylus(Me)
Dim plugIn As New SimpleStylus
Me.rts.Enabled = True
Here is the C# version:
private RealTimeStylus rts;
// We create the stylus
this.rts = new RealTimeStylus(this);
SimpleStylus plugIn = new SimpleStylus();
this.rts.Enabled = true;
and Listing 4
show the complete form code for both VB and C# versions, respectively.
|The Real Time Stylus API can be used to filter and manipulate pen input before it gets processed or recognized.|
You can now run this application and watch the output window to see stylus events being handled by the new real-time plug-in. The output you see might look similar to the following:
Packet: X 5133/ Y 4207
Packet: X 5133/ Y 4180
Packet: X 4577/ Y 3731
Packet: X 4577/ Y 3757
Expect to see a lot of Packet lines, as those events fire very fast and very often during typical drawing operations.