Compartir a través de


Ink.NearestPoint (Método) (Point, Single%)

Actualización: noviembre 2007

Devuelve el objeto Stroke más cercano a un punto especificado y devuelve el punto en el objeto Stroke que está más cerca del punto especificado.

Espacio de nombres:  Microsoft.Ink
Ensamblado:  Microsoft.Ink (en Microsoft.Ink.dll)

Sintaxis

'Declaración
Public Function NearestPoint ( _
    point As Point, _
    <OutAttribute> ByRef pointOnStroke As Single _
) As Stroke
'Uso
Dim instance As Ink
Dim point As Point
Dim pointOnStroke As Single
Dim returnValue As Stroke

returnValue = instance.NearestPoint(point, _
    pointOnStroke)
public Stroke NearestPoint(
    Point point,
    out float pointOnStroke
)
public:
Stroke^ NearestPoint(
    Point point, 
    [OutAttribute] float% pointOnStroke
)
public Stroke NearestPoint(
    Point point,
    /** @attribute OutAttribute */ /** @ref */float pointOnStroke
)
public function NearestPoint(
    point : Point, 
    pointOnStroke : float
) : Stroke

Parámetros

  • point
    Tipo: System.Drawing.Point
    El punto especificado dentro del objeto Ink, dado en coordenadas de espacio de entrada manuscrita.
  • pointOnStroke
    Tipo: System.Single%
    El punto en el objeto Stroke que está más cerca del punto especificado dentro del objeto Ink.

Valor devuelto

Tipo: Microsoft.Ink.Stroke
Devuelve el objeto Stroke que contiene un Point que se encuentra más cerca del point especificado en el objeto Ink. Si hay más de un trazo que contiene un Point que está a la misma distancia desde el Point conocido, el valor del resultado es arbitrario.

Comentarios

El parámetro pointOnStroke se define como un número de punto flotante porque el punto del objeto Stroke puede encontrarse entre dos puntos de coordenada físicos. Por ejemplo, un valor de 1,5 indica que el punto se encuentra a medio camino entre el primero y el segundo paquetes del trazo. Use este valor para dividir el objeto Stroke llamando al método Split o redondee el valor arriba o abajo para indizar un paquete en el objeto Stroke.

Ejemplos

En este ejemplo, el color del objeto Stroke que está más cercano al centro del control de la entrada manuscrita cambia a rojo. Además, se crea un nuevo objeto Stroke que va desde el punto del objeto Stroke detectado que está más cerca del centro del control de la entrada manuscrita hasta el centro del control de la entrada manuscrita.

Dim inkControl As Control = mInkOverlay.AttachedControl
' get the center of the ink control
Dim centerPt As Point = New Point(inkControl.Width / 2, inkControl.Height / 2)
Using g As Graphics = inkControl.CreateGraphics()
    ' convert center point to ink space coordinates
    mInkOverlay.Renderer.PixelToInkSpace(g, centerPt)
End Using
' get the nearest stroke
Dim pointOnStroke As Single
Dim nStroke As Stroke = mInkOverlay.Ink.NearestPoint(centerPt, pointOnStroke)
' nStroke will be null if there aren't any strokes
If Not IsNothing(nStroke) Then
    ' change the color of the nearest stroke to red
    nStroke.DrawingAttributes.Color = Color.Red
    Dim ptIdx As Integer = CType(Math.Round(pointOnStroke, MidpointRounding.ToEven), Integer)
    ' create points from the center to the nearest point on the stroke
    Dim connectPts() As Point = _
            { _
                centerPt, _
                nStroke.GetPoint(ptIdx) _
            }
    ' create the stroke
    mInkOverlay.Ink.CreateStroke(connectPts)
    inkControl.Invalidate()
End If
Control inkControl = mInkOverlay.AttachedControl;
// get the center of the ink control
Point centerPt = new Point(inkControl.Width / 2, inkControl.Height / 2);
using (Graphics g = inkControl.CreateGraphics())
{
    // convert center point to ink space coordinates
    mInkOverlay.Renderer.PixelToInkSpace(g, ref centerPt);
}

// get the nearest stroke
float pointOnStroke;
Stroke nStroke = mInkOverlay.Ink.NearestPoint(centerPt, out pointOnStroke);

// nStroke will be null if there aren't any strokes
if (nStroke != null)
{
    // change the color of the nearest stroke to red
    nStroke.DrawingAttributes.Color = Color.Red;
    int ptIdx = (int)Math.Round(pointOnStroke, MidpointRounding.ToEven);
    // create points from the center to the nearest point on the stroke
    Point[] connectPts = new Point[2] 
    {
        centerPt, 
        nStroke.GetPoint(ptIdx)
    };
    // create the stroke
    mInkOverlay.Ink.CreateStroke(connectPts);
    inkControl.Invalidate();
}

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

Vea también

Referencia

Ink (Clase)

Ink (Miembros)

NearestPoint (Sobrecarga)

Microsoft.Ink (Espacio de nombres)

Stroke

Stroke.Split