Condividi tramite


Metodo InkOverlay.HitTestSelection

Aggiornamento: novembre 2007

Restituisce un valore che indica quale parte di una selezione, se presente, è stata raggiunta durante un hit test.

Spazio dei nomi:  Microsoft.Ink
Assembly:  Microsoft.Ink (in Microsoft.Ink.dll)

Sintassi

'Dichiarazione
Public Function HitTestSelection ( _
    X As Integer, _
    Y As Integer _
) As SelectionHitResult
'Utilizzo
Dim instance As InkOverlay
Dim X As Integer
Dim Y As Integer
Dim returnValue As SelectionHitResult

returnValue = instance.HitTestSelection(X, _
    Y)
public SelectionHitResult HitTestSelection(
    int X,
    int Y
)
public:
SelectionHitResult HitTestSelection(
    int X, 
    int Y
)
public SelectionHitResult HitTestSelection(
    int X,
    int Y
)
public function HitTestSelection(
    X : int, 
    Y : int
) : SelectionHitResult

Parametri

  • X
    Tipo: System.Int32
    Posizione X, in pixel, dell'hit test.
  • Y
    Tipo: System.Int32
    Posizione Y, in pixel, dell'hit test.

Valore restituito

Tipo: Microsoft.Ink.SelectionHitResult
Membro dell'enumerazione SelectionHitResult, che specifica quale parte di una selezione, se presente, è stata raggiunta durante un hit test.

Note

Questo metodo risulta utile solo se la proprietà InkOverlay.EditingMode è impostata su Select.

Nota

Quando si esegue un'applicazione dell'input penna su un computer desktop con Windows XP impostato su 120 dpi, il metodo HitTestSelection viene spostato di un fattore di scala quando il punto fornito viene convertito dallo spazio di input penna allo spazio dei pixel.

Esempi

In questo esempio, quando viene generato l'evento MouseDown, viene effettuato un controllo per verificare se l'oggetto EditingMode è impostato su Select. In tal caso, viene chiamato il metodo HitTestSelection per determinare quale parte della selezione (se presente) è stata raggiunta. Se l'occorrenza si verifica in una delle quattro principali direzioni della bussola, come specificato dall'enumerazione SelectionHitResult, gli oggetti di tratto selezionati vengono visualizzati in un altro colore.

Private Sub mInkObject_MouseDown(ByVal sender As Object, ByVal e As CancelMouseEventArgs)

    If InkOverlayEditingMode.Select = mInkObject.EditingMode Then
        Select Case mInkObject.HitTestSelection(e.X, e.Y)
            Case SelectionHitResult.North
                ChangeSelectionColor(Color.Green)
            Case SelectionHitResult.East
                ChangeSelectionColor(Color.Red)
            Case SelectionHitResult.South
                ChangeSelectionColor(Color.Purple)
            Case SelectionHitResult.West
                ChangeSelectionColor(Color.Blue)
        End Select
    End If
End Sub

Private Sub ChangeSelectionColor(ByVal color As Color)
    Dim DA As DrawingAttributes = mInkObject.DefaultDrawingAttributes.Clone()
    DA.Color = color
    mInkObject.Selection.ModifyDrawingAttributes(DA)
    Using G As Graphics = CreateGraphics()
        ' Get the bounding box of the selection. The default is
        ' to include the width of the strokes in the calculation.
        ' The returned rectangle is measured in ink units.
        Dim rInkUnits As Rectangle = mInkObject.Selection.GetBoundingBox()

        ' In selection mode, the selected strokes are drawn inflated
        ' GetBoundingBox() does not take this into account
        ' Rectangle rInkUnits is inflated to compensate
        rInkUnits.Inflate(53, 53)

        Dim topLeft As Point = rInkUnits.Location
        Dim bottomRight As Point = rInkUnits.Location + rInkUnits.Size

        ' get a Renderer object to make the conversion
        Dim R As Renderer = New Renderer()

        ' convert the points to pixels
        R.InkSpaceToPixel(G, topLeft)
        R.InkSpaceToPixel(G, bottomRight)

        ' create a rectangle that is in pixels
        Dim rPixelUnits As Rectangle = _
            New Rectangle(topLeft, New Size(bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y))

        ' Redraw the strokes
        mInkObject.Draw(rPixelUnits)

    End Using
End Sub
private void mInkObject_MouseDown(object sender, CancelMouseEventArgs e)
{
    if (InkOverlayEditingMode.Select == mInkObject.EditingMode)
    {
        switch (mInkObject.HitTestSelection(e.X, e.Y))
        {
            case SelectionHitResult.North:
                ChangeSelectionColor(Color.Green);
                break;
            case SelectionHitResult.East:
                ChangeSelectionColor(Color.Red);
                break;
            case SelectionHitResult.South:
                ChangeSelectionColor(Color.Purple);
                break;
            case SelectionHitResult.West:
                ChangeSelectionColor(Color.Blue);
                break;
        }
    }
}

private void ChangeSelectionColor(Color color)
{
    DrawingAttributes DA = mInkObject.DefaultDrawingAttributes.Clone();
    DA.Color = color;
    mInkObject.Selection.ModifyDrawingAttributes(DA);
    using (Graphics G = CreateGraphics())
    {
        // Get the bounding box of the selection. The default is
        // to include the width of the strokes in the calculation.
        // The returned rectangle is measured in ink units.
        Rectangle rInkUnits = mInkObject.Selection.GetBoundingBox();

        // In selection mode, the selected strokes are drawn inflated
        // GetBoundingBox() does not take this into account
        // Rectangle rInkUnits is inflated to compensate
        rInkUnits.Inflate(53, 53);

        Point topLeft = rInkUnits.Location;
        Point bottomRight = rInkUnits.Location + rInkUnits.Size;

        // get a Renderer object to make the conversion
        Renderer R = new Renderer();

        // convert the points to pixels
        R.InkSpaceToPixel(G, ref topLeft);
        R.InkSpaceToPixel(G, ref bottomRight);

        // create a rectangle that is in pixels
        Rectangle rPixelUnits =
            new Rectangle(topLeft, new Size(bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y));

        // Redraw the strokes
        mInkObject.Draw(rPixelUnits);

    } 
}

Piattaforme

Windows Vista

.NET Framework e .NET Compact Framework non supportano tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.

Informazioni sulla versione

.NET Framework

Supportato in: 3.0

Vedere anche

Riferimenti

InkOverlay Classe

Membri InkOverlay

Spazio dei nomi Microsoft.Ink

SelectionHitResult