InkOverlay.HitTestSelection (Método)
Actualización: noviembre 2007
Devuelve un valor que indica qué parte de una selección, si existe, se alcanzó durante una comprobación de posicionamiento.
Espacio de nombres: Microsoft.Ink
Ensamblado: Microsoft.Ink (en Microsoft.Ink.dll)
Sintaxis
'Declaración
Public Function HitTestSelection ( _
X As Integer, _
Y As Integer _
) As SelectionHitResult
'Uso
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
Parámetros
- X
Tipo: System.Int32
La posición x, en píxeles, de la comprobación de posicionamiento.
- Y
Tipo: System.Int32
La posición y, en píxeles, de la comprobación de posicionamiento.
Valor devuelto
Tipo: Microsoft.Ink.SelectionHitResult
Un miembro de la enumeración SelectionHitResult, que especifica qué parte de una selección, si existe, se alcanzó durante una comprobación de posicionamiento.
Comentarios
Este método sólo es útil si la propiedad InkOverlay.EditingMode se establece en Select.
Nota
Al ejecutar una aplicación de entrada manuscrita en un equipo de escritorio con Windows XP establecido en 120 ppp, el método HitTestSelection se desplaza mediante un factor de escala cuando el punto proporcionado se convierte de espacio de entrada manuscrita a espacio en píxeles.
Ejemplos
En este ejemplo, cuando se desencadena el evento MouseDown, se realiza una comprobación para ver si EditingMode está establecido en Select. Si es así, se llama al método HitTestSelection para determinar qué parte de la selección se ha alcanzado (en caso de que haya alguna). Si la posición se encuentra en uno de los cuatro puntos cardinales principales, tal y como especifica la enumeración SelectionHitResult, los objetos del trazo que están seleccionados cambiarán de color.
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);
}
}
Plataformas
Windows Vista
.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.
Información de versión
.NET Framework
Compatible con: 3.0