Compartir a través de


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

Actualización: noviembre 2007

Devuelve la ubicación en el objeto Stroke más próximo a un objeto Point especificado y la distancia entre el punto y el objeto Stroke.

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

Sintaxis

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

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

Parámetros

  • pt
    Tipo: System.Drawing.Point
    El punto especificado, en coordenadas de espacio de entrada manuscrita.
  • distance
    Tipo: System.Single%
    La distancia del punto al objeto Stroke, como un índice de punto flotante.

Valor devuelto

Tipo: System.Single
Devuelve la ubicación del objeto Stroke más próximo al objeto Point especificado.

Comentarios

Un índice de punto flotante es un valor flotante que representa una ubicación situada en algún lugar entre dos puntos del objeto Stroke. Por ejemplo, si 0,0 es el primer punto del trazo y 1,0 el segundo punto, 0,5 se encontrará a mitad de camino entre el primer y el segundo punto. De igual forma, un valor de índice de punto flotante de 37,25 representa una ubicación que se encuentra en el 25 por ciento de la línea que une los puntos 37 y 38 del trazo.

Ejemplos

En este ejemplo, se examinan todos los objetos Stroke seleccionados de un objeto InkOverlay. Con el método NearestPoint, se determinan el punto del trazo que está más cerca del centro del lienzo de la entrada manuscrita y la distancia en unidades HIMETRIC desde el centro a dicho punto. Si la distancia es al menos 2000 unidades HIMETRIC, se crea un nuevo objeto Stroke que conecta el punto más próximo con el centro del lienzo 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
' examine each selected stroke
For Each S As Stroke In mInkOverlay.Selection
    ' get the index of the nearest point
    Dim distance As Single
    Dim fIdx As Single = S.NearestPoint(centerPt, distance)
    If distance >= 2000.0 Then
        ' create points from the center to the nearest point on the stroke
        Dim connectPts() As Point = _
        { _
            centerPt, _
            S.GetPoint(CType(Math.Round(fIdx, MidpointRounding.ToEven), Integer)) _
        }
        ' create the stroke
        S.Ink.CreateStroke(connectPts)
    End If
Next
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);
}

// examine each selected stroke
foreach (Stroke S in mInkOverlay.Selection)
{
    // get the index of the nearest point
    float distance;
    float fIdx = S.NearestPoint(centerPt, out distance);
    if (distance >= 2000.0)
    {
        // create points from the center to the nearest point on the stroke
        Point[] connectPts = new Point[2] 
        {
            centerPt, 
            S.GetPoint((int)Math.Round(fIdx, MidpointRounding.ToEven))
        };
        // create the stroke
        S.Ink.CreateStroke(connectPts);
    }
}

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

Stroke (Clase)

Stroke (Miembros)

NearestPoint (Sobrecarga)

Microsoft.Ink (Espacio de nombres)

Ink.NearestPoint

Ink.HitTest

Stroke.GetRectangleIntersections