Ink

Ink

Description of ink collection sample for the Tablet PC.

This application is based on the InkCollector object and demonstrates the collection of ink. The application creates a window, attaches an InkCollector object to it, and provides the user with menu choices that can be used to change the ink color, the ink width, and enable/disable ink collection.

Note: The Microsoft® Windows® XP Tablet PC Edition Software Development Kit (SDK) provides versions of this sample written in the following languages: C#, Microsoft Visual Basic® .NET, and Visual Basic 6.0. The version discussed in this section is Visual Basic .NET. The concepts are the same between versions.

Declaring the InkCollector

The application first imports the Microsoft.Ink namespace. Then, the application declares myInkCollector, which holds the InkCollector object for the form.

' The Ink namespace, which contains the Tablet PC Platform APIImports Microsoft.Ink
...
Public Class InkCollection
   Inherits Form
    ' Declare the Ink Collector object
    Private myInkCollector

Setting Things Up

The form's InkCollection_Load method handles the form's Load Leave Site event. It creates an InkCollector object assigned to the form, modifies the DefaultDrawingAttributes property of the InkCollector object, and enables the InkCollector object.

Private Sub InkCollection_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    ' Create an ink collector and assign it to this form's window
    myInkCollector = New InkCollector(Me.Handle)

    ' Set the pen width to be a medium width
    myInkCollector.DefaultDrawingAttributes.Width = MediumInkWidth

    ' If you do not modify the default drawing attributes, the default
    ' drawing attributes will use the following properties and values:
    ' ...

    ' Turn the ink collector on
    myInkCollector.Enabled = True
End Sub

The InkCollector is assigned to the form's window by assigning the form's window handle to the InkCollector object's Handle property. Ink collection is turned on by setting the InkCollector object's Enabled property to True.

The InkCollector object's DefaultDrawingAttributes property sets the default attributes that are assigned to a new cursor. To set different attributes on a new cursor, use the DrawingAttributes property of the Cursor object. To change the drawing attributes of a single stroke, use the DrawingAttributes property of the Stroke object.

Changing the Properties

The rest of this simple application consists of handlers for the various menu selections the user can make. For example, when the user chooses to change the ink color to red by selecting Red from the Ink menu, the color is changed using the Color property on InkCollector object's DefaultDrawingAttributes property in the event handler for the menu.

Private Sub miRed_Click(ByVal sender As System.Object,
                        ByVal e As System.EventArgs) Handles miRed.Click
    myInkCollector.DefaultDrawingAttributes.Color = Color.Red
End Sub

Closing the Form

The form's Dispose Leave Site method disposes the InkCollector object, myInkCollector.