Ejemplo de formulario de notificaciones automáticas

El ejemplo de reclamaciones automáticas aborda un escenario hipotético para un evaluador de seguros. El trabajo del evaluador le exige que visite con clientes en su casa o negocio y escribir su información de reclamación en un formulario. Para aumentar la productividad del evaluador, su departamento de TI desarrolla una aplicación de tableta que le permite introducir información de notificación rápidamente y precisamente a través de dos controles de lápiz: Controles InkEdit y InkPicture .

En este ejemplo, se usa un control InkEdit para cada campo de entrada de texto. Un usuario escribe la información pertinente sobre una póliza de seguro y un vehículo en estos campos con un lápiz. El control InkPicture se utiliza para agregar tinta sobre una imagen de automóvil para resaltar las áreas dañadas del automóvil. El ejemplo de notificaciones automáticas está disponible para C# y Microsoft Visual Basic .NET. En este tema se describe .NET de Visual Basic.

La clase AutoClaims se define como una subclase de System.Windows.Forms.Form y se define una clase anidada para crear y administrar capas de tinta para distintos tipos de daños. Se definen cuatro controladores de eventos para realizar las siguientes tareas:

  • Inicialización de las capas de formulario e entrada de lápiz.
  • Volver a dibujar el control InkPicture .
  • Seleccionar una capa de entrada de lápiz a través del cuadro de lista.
  • Cambiar la visibilidad de una capa de entrada de lápiz.

Nota

Las versiones de este ejemplo están disponibles en C# y Visual Basic .NET. La versión que se describe en esta sección es Visual Basic .NET. Los conceptos son los mismos entre versiones.

 

Definición de las capas de formulario e entrada de lápiz

Debe importar el espacio de nombres Microsoft.Ink :

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

A continuación, en la clase AutoClaims, se define una clase anidada InkLayer y se declara una matriz de cuatro InkLayer objetos. (InkLayer contiene un objeto Microsoft.Ink.Ink para almacenar la entrada de lápiz y los valores System.Drawing.Color y Boolean para almacenar el color y el estado oculto de la capa). Se declara un quinto objeto Ink para controlar la entrada de lápiz de InkPicture cuando todas las capas de tinta están ocultas.

' 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;

Cada capa tiene su propio objeto Ink . Hay cuatro áreas discretas de interés en la forma de notificación (cuerpo, ventanas, neumáticos y faros), por lo que se usan cuatro objetos InkLayer. Un usuario puede ver cualquier combinación de capas a la vez.

Inicialización de las capas de formulario e entrada de lápiz

El Load controlador de eventos inicializa el objeto Ink y los cuatro InkLayer objetos.

' 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);

A continuación, seleccione la primera entrada (Cuerpo) en el cuadro de lista.

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

Por último, establezca el color de entrada de lápiz del control InkPicture en la entrada del cuadro de lista seleccionada actualmente.

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

Volver a dibujar el control InkPicture

En el controlador de eventos paint heredado del control InkPicture, se comprueban las capas de tinta para determinar cuáles están ocultas. Si una capa no está oculta, el procedimiento de evento lo muestra mediante el método Draw de la propiedad Renderer. Si observa en el Examinador de objetos, verá que la propiedad Microsoft.Ink.InkPicture.Renderer se define como un objeto 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);
        }
    }          
}

Selección de una capa de entrada de lápiz a través del cuadro de lista

Cuando el usuario selecciona un elemento en el cuadro de lista, el controlador de eventos SelectedIndexChanged comprueba primero que la selección ha cambiado y que el control InkPicture no está recopilando tinta actualmente. A continuación, establece el color de entrada de lápiz del control InkPicture en el color adecuado para la capa de tinta seleccionada. Además, actualiza la casilla Ocultar capa para reflejar el estado oculto de la capa de entrada de lápiz seleccionada. Por último, el método Refresh heredado del control InkPicture se usa para mostrar solo las capas deseadas dentro del control.

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.");
        }
    }
}

Cambio de la visibilidad de una capa de entrada de lápiz

El CheckedChanged controlador de eventos comprueba primero que la selección ha cambiado y que el control InkPicture no está recopilando tinta actualmente. A continuación, actualiza el estado oculto de la capa de entrada de lápiz seleccionada, establece inkPicture control InkEnabled en FALSE, .

A continuación, la propiedad InkEnabled del control InkPicture se establece en FALSE antes de actualizar su propiedad Ink.

Por último, el control InkPicture está habilitado o deshabilitado para la parte del vehículo en particular en función de si la casilla Ocultar capa está activada y el método Refresh del control InkPicture se usa para mostrar solo las capas deseadas dentro del control.

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.");
        }
    }
}

Cerrar el formulario

En windows Form Designer código generado, los controles InkEdit y InkPicture se agregan a la lista de componentes del formulario cuando se inicializa el formulario. Cuando se cierra el formulario, se eliminan los controles InkEdit e InkPicture, así como los demás componentes del formulario, mediante el método Dispose del formulario. El método Dispose del formulario también elimina los objetos Ink creados para el formulario.

Microsoft.Ink.Ink

InkPicture Control

InkEdit Control