Auto Claims Form Sample
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 , 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.
Before the AutoClaims class is defined, the Microsoft.Ink namespace is imported.
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 and Boolean 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.
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
Every time the InkPicture control's Paint 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
The ListBox control's SelectedIndexChanged 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
The Hide Layer check box's CheckedChanged 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 method is used to display only the desired layers within the control.
inkPictVehicle.InkEnabled = Not chHideLayer.Checked Me.Refresh()
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 method. The form's Dispose method also disposes the Ink objects that are created for the form.