次の方法で共有


自動要求フォーム サンプル

自動請求のサンプルでは、保険評価者の仮定のシナリオに対処します。 評価者の仕事では、自宅やビジネスのクライアントと一緒に訪問し、請求情報をフォームに入力する必要があります。 評価者の生産性を向上させるために、IT 部門は、 InkEdit コントロールと InkPicture コントロールの 2 つのインク コントロールを使用して、迅速かつ正確に要求情報を入力できるタブレット アプリケーションを開発しています。

このサンプルでは、各テキスト入力フィールドに InkEdit コントロールを使用します。 ユーザーは、保険契約と車両に関する関連情報をペンでこれらのフィールドに入力します。 InkPicture コントロールは、自動車の画像にインクを追加して、自動車の破損した領域を強調表示するために使用されます。 自動要求のサンプルは、C# と Microsoft Visual Basic .NET で使用できます。 このトピックでは、Visual Basic .NET について説明します。

AutoClaims クラスは System.Windows.Forms.Form のサブクラスとして定義され、入れ子になったクラスは、さまざまな種類の損害に対してインクのレイヤーを作成および管理するために定義されます。 次のタスクを実行するために、4 つのイベント ハンドラーが定義されています。

  • フォームレイヤーとインクレイヤーの初期化。
  • InkPicture コントロールを再描画します。
  • リスト ボックスを使用してインク レイヤーを選択します。
  • インク レイヤーの可視性を変更する。

注意

このサンプルのバージョンは、C# と Visual Basic .NET で入手できます。 このセクションで説明するバージョンは Visual Basic .NET です。 概念は、バージョン間で同じです。

 

フォームレイヤーとインクレイヤーの定義

Microsoft.Ink 名前空間をインポートする必要があります。

Imports Microsoft.Ink
// The Ink namespace, which contains the Tablet PC Platform API
using Microsoft.Ink;

次に、AutoClaims クラスでは、入れ子になった InkLayer クラスが定義され、4 つの InkLayer オブジェクトの配列が宣言されます。 (InkLayer には、インクを格納するための Microsoft.Ink.Ink オブジェクトと、レイヤーの色と非表示の状態を格納するための System.Drawing.Colorブール 値が含まれています)。5 番目の Ink オブジェクトは、すべてのインク レイヤーが非表示のときに InkPicture のインクを処理するように宣言されています。

' Declare the array of ink layers used the vehicle illustration.
Dim inkLayers(3) As InkLayer

' Declare an empty ink object (used when we don't want to draw
' any ink).
Dim emptyInk As Ink

' Declare a value to hold the index of selected ink
Dim selectedIndex As Integer

' Declare a value to hold whether the selected ink is hidden
Dim selectedHidden As Boolean 
// Declare the array of ink layers used the vehicle illustration.
InkLayer[] inkLayers;

// Declare an empty ink object (used when we don't want to draw
// any ink).
Ink emptyInk;

// Declare a value to hold the index of selected ink
int selectedIndex = -1;

// Declare a value to hold whether the selected ink is hidden
bool selectedHidden = false;

各レイヤーには、独自の Ink オブジェクトがあります。 クレーム フォームには 4 つの個別の領域 (ボディ、ウィンドウ、タイヤ、ヘッドライト) があるため、4 つの InkLayer オブジェクトが使用されます。 ユーザーは、レイヤーの任意の組み合わせを一度に表示できます。

フォームレイヤーとインクレイヤーの初期化

イベント ハンドラーは LoadInk オブジェクトと 4 つの InkLayer オブジェクトを初期化します。

' Initialize the empty ink
emptyInk = New Ink()

' Initialize the four different layers of ink on the vehicle diagram:  
' vehicle body, windows, tires, and headlights.
inkLayers(0) = New InkLayer(New Ink(), Color.Red, False)
inkLayers(1) = New InkLayer(New Ink(), Color.Violet, False)
inkLayers(2) = New InkLayer(New Ink(), Color.LightGreen, False)
inkLayers(3) = New InkLayer(New Ink(), Color.Aqua, False)
// Initialize the empty ink
emptyInk = new Ink();

// Initialize the four different layers of ink on the vehicle diagram:  
// vehicle body, windows, tires, and headlights.
inkLayers = new InkLayer[4];
inkLayers[0] = new InkLayer(new Ink(), Color.Red, false);
inkLayers[1] = new InkLayer(new Ink(), Color.Violet, false);
inkLayers[2] = new InkLayer(new Ink(), Color.LightGreen, false);
inkLayers[3] = new InkLayer(new Ink(), Color.Aqua, false);

次に、リスト ボックスで最初のエントリ (本文) を選択します。

' By default, select the first ink layer
lstAnnotationLayer.SelectedIndex = 0
// By default, select the first ink layer
lstAnnotationLayer.SelectedIndex = 0;

最後に、 InkPicture コントロールのインクの色を、現在選択されているリスト ボックス エントリに設定します。

inkPictVehicle.DefaultDrawingAttributes.Color =
      inkLayers(lstAnnotationLayer.SelectedIndex).ActiveColor
inkPictVehicle.DefaultDrawingAttributes.Color = inkLayers[lstAnnotationLayer.SelectedIndex].ActiveColor;

InkPicture コントロールの再描画

InkPicture コントロールの継承された Paint イベント ハンドラーで、インク レイヤーがチェックされ、非表示になっているものが特定されます。 レイヤーが非表示でない場合、イベント プロシージャは Renderer プロパティの Draw メソッドを使用してレイヤーを表示します。 オブジェクト ブラウザーを見ると、Microsoft.Ink.InkPicture.Renderer プロパティが Microsoft.Ink.Renderer オブジェクトとして定義されていることがわかります。

Private Sub inkPictVehicle_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles inkPictVehicle.Paint
    Dim layer As InkLayer

    ' Cycle through each ink layer.  If it is visible, paint it.
    ' Note that it is necessary to customize the paint
    ' behavior, since we want to hide/show different ink layers.
    For Each layer In inkLayers
        If (Not layer.Hidden) Then
            inkPictVehicle.Renderer.Draw(e.Graphics, layer.ActiveInk.Strokes)
        End If
    Next
End Sub
private void inkPictVehicle_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
    // Cycle through each ink layer.  If it is visible, paint it.
    // Note that it is necessary to customize the paint
    // behavior, since we want to hide/show different ink layers.
    foreach (InkLayer layer in inkLayers)
    {
        if (!layer.Hidden)
        {
             inkPictVehicle.Renderer.Draw(e.Graphics,layer.ActiveInk.Strokes);
        }
    }          
}

リスト ボックスからインク レイヤーを選択する

ユーザーがリスト ボックス内の項目を選択すると、 SelectedIndexChanged イベント ハンドラーは最初に、選択範囲が変更されたことと 、InkPicture コントロールが現在インクを収集していないかどうかを確認します。 次に、InkPicture コントロールのインクの色を、選択したインク レイヤーの適切な色に設定します。 また、[レイヤーの非表示] チェック ボックスが更新され、選択したインク レイヤーの非表示の状態が反映されます。 最後に、InkPicture コントロールの継承された Refresh メソッドを使用して、コントロール内の目的のレイヤーのみを表示します。

Private Sub chHideLayer_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chHideLayer.CheckedChanged

    ' Provided that the new checked hidden value is different than
    ' the previous value...
    If (Not (chHideLayer.Checked = selectedHidden)) Then
        If (Not (inkPictVehicle.CollectingInk)) Then

            ' Update the array indicating the visibility of each ink layer
            inkLayers(lstAnnotationLayer.SelectedIndex).Hidden = chHideLayer.Checked

            ' Set the active ink object to the selected ink
            ' Note that if the current layer is not visible, empty
            ' ink is used to prevent flicker.
            inkPictVehicle.InkEnabled = False
            If (chHideLayer.Checked) Then
                inkPictVehicle.Ink = emptyInk
            Else
                inkPictVehicle.Ink = inkLayers(lstAnnotationLayer.SelectedIndex).ActiveInk
            End If

            ' Update the previous checkbox value to the current
            selectedHidden = chHideLayer.Checked

            ' If the layer is marked hidden, disable ink collection
            inkPictVehicle.InkEnabled = Not chHideLayer.Checked

            Me.Refresh()
       Else
            ' If ink collection is enabled, the active ink cannot be changed
            ' and it is necessary to restore the checkbox to its previous value.
            chHideLayer.Checked = selectedHidden
            MessageBox.Show("Cannot change visiblity while collecting ink.")
       End If
   End If
End Sub
private void lstAnnotationLayer_SelectedIndexChanged(object sender, System.EventArgs e)
{
    // Provided that the new selected index value is different than
    // the previous value...
    if (lstAnnotationLayer.SelectedIndex != selectedIndex) 
    {
        if (!inkPictVehicle.CollectingInk)
        {
            // Set the ink and visiblity of the current ink layer
            inkPictVehicle.DefaultDrawingAttributes.Color = inkLayers[lstAnnotationLayer.SelectedIndex].ActiveColor;
            chHideLayer.Checked = inkLayers[lstAnnotationLayer.SelectedIndex].Hidden;

            // Set the active ink object to the selected ink
            // Note that if the current layer is not visible, empty
            // ink is used to prevent flicker.
            inkPictVehicle.InkEnabled = false;
            inkPictVehicle.Ink = chHideLayer.Checked?emptyInk:inkLayers[lstAnnotationLayer.SelectedIndex].ActiveInk;
            inkPictVehicle.InkEnabled = !chHideLayer.Checked;
    
            selectedIndex = lstAnnotationLayer.SelectedIndex;

            this.Refresh();
        }
        else 
        {
            // If ink collection is enabled, the active ink cannot be changed
            // and it is necessary to restore the selection to its previous value.
            lstAnnotationLayer.SelectedIndex = selectedIndex;
            MessageBox.Show("Cannot change active ink while collecting ink.");
        }
    }
}

インク レイヤーの可視性を変更する

イベント ハンドラーは CheckedChanged 、まず、選択範囲が変更されていること、および InkPicture コントロールが現在インクを収集していないかどうかを確認します。 次に、選択したインク レイヤーの非表示の状態を更新し、InkPicture コントロールの InkEnabled を FALSE に設定します。

次に、InkPicture コントロールの InkEnabled プロパティは、Ink プロパティを更新する前に FALSE に設定されます。

最後に、[レイヤーの非表示] チェック ボックスが選択されているかどうかに基づいて、特定の車両パーツに対して InkPicture コントロールを有効または無効にし、InkPicture コントロールの Refresh メソッドを使用して、コントロール内の目的のレイヤーのみを表示します。

Private Sub chHideLayer_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chHideLayer.CheckedChanged

    ' Provided that the new checked hidden value is different than
    ' the previous value...
    If (Not (chHideLayer.Checked = selectedHidden)) Then
        If (Not (inkPictVehicle.CollectingInk)) Then

            ' Update the array indicating the visibility of each ink layer
            inkLayers(lstAnnotationLayer.SelectedIndex).Hidden = chHideLayer.Checked

            ' Set the active ink object to the selected ink
            ' Note that if the current layer is not visible, empty
            ' ink is used to prevent flicker.
            inkPictVehicle.InkEnabled = False
            If (chHideLayer.Checked) Then
                inkPictVehicle.Ink = emptyInk
            Else
                inkPictVehicle.Ink = inkLayers(lstAnnotationLayer.SelectedIndex).ActiveInk
            End If

            ' Update the previous checkbox value to the current
            selectedHidden = chHideLayer.Checked

            ' If the layer is marked hidden, disable ink collection
            inkPictVehicle.InkEnabled = Not chHideLayer.Checked

            Me.Refresh()
        Else
            ' If ink collection is enabled, the active ink cannot be changed
            ' and it is necessary to restore the checkbox to its previous value.
            chHideLayer.Checked = selectedHidden
            MessageBox.Show("Cannot change visiblity while collecting ink.")
        End If
    End If
End Sub
private void chHideLayer_CheckedChanged(object sender, System.EventArgs e)
{
    // Provided that the new checked hidden value is different than
    // the previous value...
    if (chHideLayer.Checked != selectedHidden) 
    {
        if (!inkPictVehicle.CollectingInk)
        {
            // Update the array indicating the visibility of each ink layer
            inkLayers[lstAnnotationLayer.SelectedIndex].Hidden = chHideLayer.Checked;

            // Set the active ink object to the selected ink
            // Note that if the current layer is not visible, empty
            // ink is used to prevent flicker.
            inkPictVehicle.InkEnabled = false;
            inkPictVehicle.Ink = chHideLayer.Checked?emptyInk:inkLayers[lstAnnotationLayer.SelectedIndex].ActiveInk;
 
            // If the layer is marked hidden, disable ink collections
            inkPictVehicle.InkEnabled = !chHideLayer.Checked;

            // Update the previous checkbox value to reflect the current
            selectedHidden = chHideLayer.Checked;

            this.Refresh();
        }
        else 
        {
            // If ink collection is enabled, the active ink cannot be changed
            // and it is necessary to restore the checkbox to its previous value.
            chHideLayer.Checked = selectedHidden;
            MessageBox.Show("Cannot change visiblity while collecting ink.");
        }
    }
}

フォームを閉じる

Windows フォーム Designer生成されたコードでは、フォームの初期化時に InkEdit コントロールと InkPicture コントロールがフォームのコンポーネント リストに追加されます。 フォームが閉じると、InkEdit コントロールと InkPicture コントロールが、フォームの Dispose メソッドによってフォームの他のコンポーネントと同様に 破棄 されます。 フォームの Dispose メソッドは、フォーム用に作成された Ink オブジェクトも破棄します。

Microsoft.Ink.Ink

InkPicture コントロール

InkEdit コントロール