此應用程式是以 InkCollector 物件為基礎,並示範筆跡的集合。 應用程式會建立視窗、附加 InkCollector 物件,並提供使用者可用來變更筆跡色彩、筆跡寬度,以及啟用和停用筆跡收集的功能表選項。
注意
本節中討論的版本是 Visual Basic .NET。 這些概念在範例連結庫中的其他語言版本之間相同。
宣告 InkCollector
應用程式會先匯入 Microsoft.Ink 命名空間。 然後,應用程式會宣告 myInkCollector,其會保存表單 InkCollector 物件。
' The Ink namespace, which contains the Tablet PC Platform APIImports Microsoft.Ink
...
Public Class InkCollection
Inherits Form
' Declare the Ink Collector object
Private myInkCollector
設置內容
表單的 InkCollection_Load 方法會處理表單的 Load 事件。 它會建立指派給表單的 InkCollector 物件,修改 InkCollector 物件的 DefaultDrawingAttributes 属性,並啟用 InkCollector 物件。
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
InkCollector 指派給表單視窗,方法是將表單的視窗句柄指派給 InkCollector 物件的 Handle 屬性。 將 InkCollector 物件的 Enabled 屬性設定 為 TRUE,以啟用墨跡收集功能。
InkCollector 物件的 DefaultDrawingAttributes 屬性會設定指派給新游標的預設屬性。 若要在新的游標上設定不同的屬性,請使用 Cursor 物件的 DrawingAttributes 屬性。 若要變更單一筆劃的繪圖屬性,請使用 Stroke 物件的 DrawingAttributes 屬性。
變更屬性
此簡單應用程式的其他部分由處理使用者各種選單選項的處理程式構成。 例如,當使用者從 [筆跡] 功能表中選取 [紅色] 來選擇將筆跡色彩變更為紅色時,會使用 InkCollector 上的 Color 属性來變更色彩, 物件的 DefaultDrawingAttributes 屬性。
Private Sub miRed_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles miRed.Click
myInkCollector.DefaultDrawingAttributes.Color = Color.Red
End Sub
關閉表單
表單的 Dispose 方法會釋放 InkCollector 物件,myInkCollector。