Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
L'esempio di sinistri auto affronta uno scenario ipotetico per un perito assicurativo. Il lavoro dell'assessore richiede di visitare i clienti a casa loro o presso le loro attività e di immettere le loro informazioni relative alla richiesta in un modulo. Per aumentare la produttività del valutatore, il suo reparto IT sviluppa un'applicazione per tablet che gli consente di immettere rapidamente e accuratamente le informazioni sul sinistro tramite due controlli penna: InkEdit e InkPicture.
In questo esempio viene usato un controllo InkEdit per ogni campo di input di testo. Un utente immette le informazioni pertinenti su un'assicurazione e un veicolo in questi campi con una penna. Il controllo InkPicture viene utilizzato per aggiungere inchiostro su un'immagine dell'automobile per evidenziare le aree danneggiate dell'automobile. L'esempio di richieste di indennizzo automatiche è disponibile per C# e Microsoft Visual Basic .NET. In questo argomento viene descritto Visual Basic .NET.
La classe AutoClaims viene definita come sottoclasse di System.Windows.Forms.Form e una classe annidata viene definita per la creazione e la gestione di livelli di inchiostro per diversi tipi di danni. Per eseguire le attività seguenti vengono definiti quattro gestori eventi:
- Inizializzazione del modulo e degli strati di inchiostro.
- Ridisegno del controllo InkPicture.
- Selezionare un livello di inchiostro attraverso la casella di riepilogo.
- Modificare la visibilità di uno strato di inchiostro.
Nota
Le versioni di questo esempio sono disponibili in C# e Visual Basic .NET. La versione descritta in questa sezione è Visual Basic .NET. I concetti sono gli stessi tra le versioni.
Definizione dei livelli modulo e inchiostro
È necessario importare lo spazio dei nomi Microsoft.Ink.
Imports Microsoft.Ink
// The Ink namespace, which contains the Tablet PC Platform API
using Microsoft.Ink;
Nella classe AutoClaims viene quindi definita una classe InkLayer
annidata e viene dichiarata una matrice di quattro oggetti InkLayer
. InkLayer contiene un oggetto Microsoft.Ink.Ink per l'archiviazione dell'inchiostro e System.Drawing.Color e valori booleani per archiviare il colore e lo stato nascosto del livello. Un quinto oggetto Ink viene dichiarato per gestire l'inchiostro per il InkPicture quando tutti i livelli di inchiostro sono nascosti.
' 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;
Ogni livello ha un proprio oggetto inchiostro. Ci sono quattro aree discrete di interesse nel modulo di reclamo (carrozzeria, finestre, pneumatici e fari), quindi vengono utilizzati quattro oggetti InkLayer. Un utente può visualizzare contemporaneamente qualsiasi combinazione di livelli.
Inizializzazione dei livelli Modulo e Strati di inchiostro
Il gestore eventi Load
inizializza l'oggetto Ink e i quattro oggetti 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);
Selezionare quindi la prima voce (Corpo) nella casella di riepilogo.
' By default, select the first ink layer
lstAnnotationLayer.SelectedIndex = 0
// By default, select the first ink layer
lstAnnotationLayer.SelectedIndex = 0;
Infine, impostare il colore dell'inchiostro per il controllo InkPicture sulla voce attualmente selezionata della casella di selezione.
inkPictVehicle.DefaultDrawingAttributes.Color =
inkLayers(lstAnnotationLayer.SelectedIndex).ActiveColor
inkPictVehicle.DefaultDrawingAttributes.Color = inkLayers[lstAnnotationLayer.SelectedIndex].ActiveColor;
Ridisegno del controllo InkPicture
Nel gestore dell'evento Paint ereditato del controllo InkPicture, si verificano i livelli di inchiostro per determinare quali sono nascosti. Se un livello non è nascosto, la routine evento la visualizza utilizzando il metodo Draw della proprietà Renderer. Se cerchi nel Visualizzatore oggetti, vedrai che la proprietà Microsoft.Ink.InkPicture.Renderer è definita come un oggetto 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);
}
}
}
Selezionare un livello inchiostro tramite la casella di elenco
Quando l'utente seleziona un elemento nella casella di elenco, il gestore eventi SelectedIndexChanged controlla prima che la selezione sia stata modificata e che il controllo InkPicture non stia attualmente raccogliendo inchiostro. Quindi imposta il colore dell'inchiostro del controllo InkPicture sul colore appropriato per il livello di inchiostro selezionato. Inoltre, aggiorna la casella di controllo Nasconde livello per mostrare lo stato di visibilità del livello di inchiostro selezionato. Infine, il metodo Refresh ereditato del controllo InkPicture viene usato per visualizzare solo i livelli desiderati all'interno del controllo.
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 visibility 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.");
}
}
}
Modifica della visibilità di un livello inchiostro
Il gestore dell'evento CheckedChanged
verifica innanzitutto che la selezione sia stata modificata e che il controllo InkPicture non stia attualmente raccogliendo input penna. Aggiorna quindi lo stato nascosto del livello di inchiostro selezionato e imposta la proprietà InkEnabled del controllo InkPicture su FALSE.
Successivamente, la proprietà InkEnabled del controllo InkPicture è impostata su FALSE prima di aggiornare la relativa proprietà Ink.
Infine, il controllo InkPicture è abilitato o disabilitato per la parte specifica del veicolo in base al fatto che sia selezionata la casella di controllo Nascondi livello e il metodo refresh del controllo InkPicture viene utilizzato per visualizzare solo i livelli desiderati all'interno del controllo.
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.");
}
}
}
Chiusura del modulo
Nel codice generato dal Progettazione di Windows Form, i controlli InkEdit e InkPicture vengono aggiunti all'elenco dei componenti del form quando la finestra viene inizializzata. Quando la maschera viene chiusa, i controlli InkEdit e InkPicture vengono eliminati, nonché gli altri componenti del form, dal metodo dispose del modulo. Il metodo Dispose del form elimina anche gli oggetti Ink creati per il form.
Argomenti correlati