Partager via


Auto Claims Form Sample

Auto Claims Form Sample

Description of auto claims form sample.

The Auto Claims sample addresses a hypothetical scenario for an insurance assessor. The assessor's work requires him or her to visit with clients at their home or business and to enter their claim information into a form. To increase the assessor's productivity, his IT department develops a tablet application that enables him or her to quickly and accurately enter claim information through two ink controls: InkEdit Control and InkPicture Control.

In this sample, an InkEdit control is used for each text input field. A user enters the relevant information about an insurance policy and vehicle into these fields with a pen. The InkPicture control is used to add ink over an automobile image to highlight damaged areas of the automobile. The Auto Claims sample is available for C# and Microsoft® Visual Basic® .NET. This topic describes the Visual Basic .NET.

The AutoClaims class is defined as a subclass of System.Windows.Forms.Form Leave Site, and a nested class is defined for creating and managing layers of ink for different types of damage. Four event handlers are defined to perform the following tasks:

  • Initializing the form and ink layers.
  • Redrawing the InkPicture control.
  • Selecting an ink layer through the list box.
  • Changing the visibility of an ink layer.

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

Defining the Form and Ink Layers

Before the AutoClaims class is defined, the Microsoft.Ink namespace is imported.

    Imports Microsoft.Ink

Next, in the AutoClaims class, a nested InkLayer class is defined and an array of four InkLayer objects is declared. (InkLayer contains a Microsoft.Ink.Ink object for storing ink, and System.Drawing.Color Leave Site and Boolean Leave Site values for storing the color and hidden state of the layer.) A fifth Ink object is declared to handle ink for the InkPicture when all of the ink layers are hidden.

    Dim InkLayers(3) As InkLayer
    Dim emptyInk As Ink

Each layer has its own Ink object. Because there are four discrete areas of interest in the claim form (body, windows, tires, and headlights), four InkLayer objects are used. In this manner, a user can view any combination of layers at once.

Initializing the Form and Ink Layers

In the AutoClaim form's Load Leave Site event handler, the Ink object and the four InkLayer objects are initialized.

    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)

Then, the first entry (Body) in the list box is selected by default.

    lstAnnotationLayer.SelectedIndex = 0

Finally, the ink color for the InkPicture control is set to the currently selected list box entry.

    inkPictVehicle.DefaultDrawingAttributes.Color = inkLayers(lstAnnotationLayer.SelectedIndex).ActiveColor

Redrawing the InkPicture Control

Every time the InkPicture control's Paint Leave Site event occurs, the ink layers are checked to determine which of them are hidden. If a layer is not hidden, it is displayed by using the Renderer property's Draw method (notice in the Object Browser that the InkPicture.Renderer property is defined as a Microsoft.Ink.Renderer object):

    Dim layer As InkLayer
    For Each layer In inkLayers
        If (Not layer.Hidden) Then
            inkPictVehicle.Renderer.Draw(e.Graphics, layer.ActiveInk.Strokes)
        End If
    Next

Selecting an Ink Layer through the List Box

The ListBox Leave Site control's SelectedIndexChanged Leave Site event handler first checks that the selection has changed and that the InkPicture control is not currently collecting ink, and then the ink color of the InkPicture control is set to the appropriate color for the selected ink layer. Also, the Hide Layer check box is updated to reflect the selected ink layer's hidden status.

' Provided that the new selected index value is different than
' the previous value...
If (Not (lstAnnotationLayer.SelectedIndex = selectedIndex)) Then
    If (Not inkPictVehicle.CollectingInk) Then

        ' Set the ink and visiblity of the current ink layer
        inkPictVehicle.DefaultDrawingAttributes.Color = inkLayers(lstAnnotationLayer.SelectedIndex).ActiveColor
        chHideLayer.Checked = inkLayers(lstAnnotationLayer.SelectedIndex).Hidden

Next, the InkEnabled property is set to False before loading an Ink object, and then reset to True after the object is loaded.

        inkPictVehicle.InkEnabled = False
        If (chHideLayer.Checked) Then
            inkPictVehicle.Ink = emptyInk
        Else
            inkPictVehicle.Ink = inkLayers(lstAnnotationLayer.SelectedIndex).ActiveInk
        End If
        inkPictVehicle.InkEnabled = True

Finally, the InkPicture control's Refresh Leave Site method is used to display only the desired layers within the control.

Changing the Visibility of an Ink Layer

The Hide Layer check box's CheckedChanged Leave Site event handler first checks that the selection has changed and that the InkPicture control is not currently collecting ink, and then updates the selected ink layer's hidden status.

If (Not (chHideLayer.Checked = selectedHidden)) Then
    If (Not (inkPictVehicle.CollectingInk)) Then

        inkLayers(lstAnnotationLayer.SelectedIndex).Hidden = chHideLayer.Checked

Next, the InkPicture control's InkEnabled property is set to False before updating its Ink property.

        inkPictVehicle.InkEnabled = False
        If (chHideLayer.Checked) Then
            inkPictVehicle.Ink = emptyInk
        Else
            inkPictVehicle.Ink = inkLayers(lstAnnotationLayer.SelectedIndex).ActiveInk
        End If

Finally, the InkPicture control is either enabled or disabled for the particular vehicle part based on whether the Hide Layer check box is selected, and the InkPicture control's Refresh Leave Site method is used to display only the desired layers within the control.

        inkPictVehicle.InkEnabled = Not chHideLayer.Checked
        Me.Refresh()

Note: The CheckedChanged Leave Site event occurs either when a user selects or clears a check box or the list box event handler updates the check box.

Closing the Form

In the Windows Form Designer generated code, the InkEdit and InkPicture controls are added to the form's component list when the form is initialized. When the form closes, the InkEdit and InkPicture controls are disposed, as well as the other components of the form, by the form's Dispose Leave Site method. The form's Dispose Leave Site method also disposes the Ink objects that are created for the form.