More Power with the InkOverlay
The second class of interest is the InkOverlay class, which is a specialized version of the InkCollector class. It provides everything the Ink collector provides, plus added functionality, such as selection and manipulation of Ink. You can simply replace all the references to InkCollector in your previous example with InkOverlay and things will work as they did before. And you now have new features available, such as the ability to switch the overlay into selection mode:
|Figure 4. Selecting Ink: Selecting Ink with lasso selection is supported by the InkOverlay class, but not by the InkCollector class.|
Visual Basic .NET's version is identical except for the semicolon.
shows an example of the InkOverlay's selection mode (lasso selection) in action.
Both the InkCollector and InkOverlay classes fire events related to Ink input. For instance, you can use the CursorInRange
event to detect whenever the pen is moved within about a quarter of an inch of the display surface (electromagnetic digitizers can detect the pen while it is still in the air). For instance, you can use this event to detect whether the pen tip, or the blunt end of the pen is about to tap on the display and then switch the overlay class into edit or erase mode. To handle this event in C#, you need to wire up an event handler:
Then, you need to write the code that handles the event:
private void overlay_CursorInRange(object sender,
In Visual Basic, you need to make sure that the overlay is defined using WithEvents:
Private WithEvents overlay _
You can then handle the event in the following fashion:
Private Sub overlay_CursorInRange( _
ByVal sender As Object, ByVal e _
As InkCollectorCursorInRangeEventArgs) _
If e.Cursor.Inverted Then
Me.overlay.EditingMode = _
Me.overlay.EditingMode = _
This implements end-of-pen erasing. Of course, you can also use the same event for a number of other purposes. Make sure to explore some of the other available events.
Other Ink Alternatives
InkCollector and InkOverlay objects gather pen input information and interpret it as Ink or gestures. Sometimes you do not want to collect Ink at all and you want to interpret pen data in a different fashion. Or perhaps it is necessary to manipulate pen data before it gets interpreted as Ink. Maybe performance is of utmost importance, or maybe you want to implement an unusual way to render Ink in real time. In those scenarios, an API known as the Real Time Stylus API is the way to go.
|The InkOverlay is a powerful version of the InkCollector.|
In Windows Vista (the next version of Windows), Microsoft has moved Ink support into the core operating system. The new Windows Presentation Foundation (WPFformerly known as Avalon) UI technology supports Ink natively on all versions of Windows. The magic object to look for here is known as InkCanvas.
Tablet PC development is much simpler than most developers who have not been exposed to this environment might expect. There are many opportunities and areas that provide a lot of functionality for those who are interested. Taking advantage of those features is what this special CoDe Focus issue is all about.