Ink コレクションのサンプル

このアプリケーションは InkCollector オブジェクトに基づいており、インクのコレクションを示しています。 アプリケーションは、ウィンドウを作成し、InkCollector オブジェクトをそれにアタッチし、ユーザーに、インクの色、インクの幅の変更、インク コレクションの有効化と無効化に使用できるメニューの選択肢を提供します。

注意

このセクションで説明するバージョンは Visual Basic .NET です。 概念は、サンプル ライブラリ内の他の言語バージョン間で同じです。

 

InkCollector の宣言

アプリケーションは最初に Microsoft.Ink 名前空間をインポートします。 次に、フォームの myInkCollectorInkCollector オブジェクトを保持する を宣言します。

' 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 プロパティを使用します。 1 つのストロークの描画属性を変更するには、Stroke オブジェクトの DrawingAttributes プロパティを使用します。

プロパティの変更

この単純なアプリケーションの残りの部分は、ユーザーが行うことができるさまざまなメニュー選択のハンドラーで構成されます。 たとえば、ユーザーが [インク] メニューから [赤] を選択してインクの色を赤に変更すると、メニューのイベント ハンドラーで InkCollector オブジェクトの DefaultDrawingAttributes プロパティの Color プロパティを使用して色が変更されます。

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 メソッドは、myInkCollectorInkCollector オブジェクト を破棄します。