Metodo Ink.NearestPoint (Point, Single%, Single%)
Aggiornamento: novembre 2007
Restituisce l'oggetto Stroke più vicino al punto specificato e il punto sull'oggetto Stroke che è più vicino al punto specificato; inoltre restituisce la distanza tra il punto specificato e il punto più vicino sull'oggetto Stroke nell'oggetto Ink.
Spazio dei nomi: Microsoft.Ink
Assembly: Microsoft.Ink (in Microsoft.Ink.dll)
Sintassi
'Dichiarazione
Public Function NearestPoint ( _
point As Point, _
<OutAttribute> ByRef pointOnStroke As Single, _
<OutAttribute> ByRef distanceFromPacket As Single _
) As Stroke
'Utilizzo
Dim instance As Ink
Dim point As Point
Dim pointOnStroke As Single
Dim distanceFromPacket As Single
Dim returnValue As Stroke
returnValue = instance.NearestPoint(point, _
pointOnStroke, distanceFromPacket)
public Stroke NearestPoint(
Point point,
out float pointOnStroke,
out float distanceFromPacket
)
public:
Stroke^ NearestPoint(
Point point,
[OutAttribute] float% pointOnStroke,
[OutAttribute] float% distanceFromPacket
)
public Stroke NearestPoint(
Point point,
/** @attribute OutAttribute */ /** @ref */float pointOnStroke,
/** @attribute OutAttribute */ /** @ref */float distanceFromPacket
)
public function NearestPoint(
point : Point,
pointOnStroke : float,
distanceFromPacket : float
) : Stroke
Parametri
- point
Tipo: System.Drawing.Point
Punto specificato all'interno dell'oggetto Ink, specificato nelle coordinate dello spazio di input penna.
- pointOnStroke
Tipo: System.Single%
Punto sull'oggetto Stroke più vicino al punto specificato nell'oggetto Ink.
- distanceFromPacket
Tipo: System.Single%
Distanza tra il punto specificato e l'oggetto Stroke più vicino nell'oggetto Ink.
Valore restituito
Tipo: Microsoft.Ink.Stroke
Oggetto Stroke contenente un oggetto Point che si trova più vicino al punto specificato nell'oggetto Ink. Se più tratti contengono un oggetto Point che si trova alla medesima distanza dall'oggetto Point noto, il valore di questo risultato è arbitrario.
Note
Il parametro distanceFromPacket descrive la distanza dal punto specificato all'involucro dell'oggetto Stroke. È la distanza tra i due punti meno metà della proprietà Width dell'oggetto DrawingAttributes dell'oggetto Stroke.
Esempi
In questo esempio, se un oggetto Stroke contiene un punto compreso all'interno delle 500 unità HIMETRIC del centro del controllo dell'input penna, il colore dell'oggetto Stroke viene modificato in rosso. Inoltre, viene creato un nuovo oggetto Stroke che viene eseguito dal punto dell'oggetto Stroke rilevato che è più vicino al centro del controllo dell'input penna al centro del controllo dell'input penna.
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 distanceFromPacket As Single
Dim nStroke As Stroke = mInkOverlay.Ink.NearestPoint(centerPt, pointOnStroke, distanceFromPacket)
' nStroke will be null if there aren't any strokes
If Not IsNothing(nStroke) And distanceFromPacket <= 500.0 Then
' change the color of the nearest stroke to red
nStroke.DrawingAttributes.Color = Color.Red
'Dim ptIdx As Integer = DirectCast(Math.Round(pointOnStroke, MidpointRounding.ToEven), Integer)
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;
float distanceFromPacket;
Stroke nStroke = mInkOverlay.Ink.NearestPoint(centerPt, out pointOnStroke, out distanceFromPacket);
// nStroke will be null if there aren't any strokes
if (nStroke != null && distanceFromPacket <= 500.0)
{
// 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();
}
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