FujitsuStylistic.com

Adding Ink to Existing Applications

The final part of this chapter is devoted to adding ink to existing Windows Forms applications. You can certainly add controls such as InkPicture or InkEdit, or you can use objects such as InkOverlay, but the easiest way to add ink to an existing application is via the PenInputPanel object. As an attachable object, it allows you to add in-place pen input to your applications. You can choose either handwriting or keyboard options for the input method for the Pen Input Panel. Your end user will have the ability to switch between input methods using buttons on the user interface.
Let's create a simple example using the Pen Input Panel. Begin by creating a new Window Forms application in VB .NET. Next, add four standard TextBox controls to the window to simulate an existing VB application. Next, we need to add a reference to the Tablet PC API 1.5. Make sure to select the 1.5 API because version 1 does not include the PenInputPanel object.
The next step is to add the following Imports statement to the Code Editor: Imports Microsoft.Ink Add the following code to create the Pen Input Panel:
Dim thePenInputPanel As New PenInputPanel() Now that we have created the Pen Input Panel, we need to attach it to a control before we can use it. We have two options for this. The first is to create three separate Pen Input Panels and then assign each of them to one of the text boxes. The other option is to create the single Pen Input Panel and then attach the control as necessary. In our case, we are going to attach the controls during the Mouse_Down events of the first three TextBox controls. We'll leave the last one alone so we can verify that the Pen Input Panel only works when we attach it to a control. Here are the procedures and the code:
Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown thePenInputPanel.AttachedEditControl = TextBox1 End Sub Private Sub TextBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox2.MouseDown thePenInputPanel.AttachedEditControl = TextBox2 End Sub
Private Sub TextBox3_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox3.MouseDown thePenInputPanel.AttachedEditControl = TextBox3 End Sub You can now test the application. You should try to use your pen to click in the first three text boxes to verify that it works (see Figure 13.8). Additionally, try clicking in the fourth text box to verify that the Pen Input Panel does not appear. Lastly, if you have a mouse attached, try clicking in the text boxes with a mouse. This should verify that the Pen Input Panel does not work unless a pen is being used.