StylusPoint Structure

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Represents a single point collected while the user is entering ink strokes with the stylus or mouse.

Namespace:  System.Windows.Input
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Structure StylusPoint
public struct StylusPoint
<StylusPoint .../>

The StylusPoint type exposes the following members.

Constructors

  Name Description
Public methodSupported by Silverlight for Windows Phone StylusPoint Initializes a new instance of the StylusPoint class.

Top

Properties

  Name Description
Public propertySupported by Silverlight for Windows Phone PressureFactor Gets or sets the pressure factor of the stylus on the screen.
Public propertySupported by Silverlight for Windows Phone X Gets or sets the value for the x-coordinate of the StylusPoint.
Public propertySupported by Silverlight for Windows Phone Y Gets or sets the value for the y-coordinate of the StylusPoint.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows Phone Equals Indicates whether this instance and a specified object are equal. (Inherited from ValueType.)
Protected methodSupported by Silverlight for Windows Phone Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone GetHashCode Returns the hash code for this instance. (Inherited from ValueType.)
Public methodSupported by Silverlight for Windows Phone GetType Gets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows Phone MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone ToString Returns the fully qualified type name of this instance. (Inherited from ValueType.)

Top

Remarks

The StylusPoint structure represents a single point. All StylusPoint objects contain properties that indicate the (x, y) coordinates and the pressure.

NoteNote:

You can get the relevant PressureFactor only if the device supports it. Otherwise, PressureFactor will have a default value of 0.5.

Multiple StylusPoint objects typically make up a Stroke object. The Stroke object stores the stylus points in the StylusPoints property.

Examples

The following code example displays the x-coordinate, y-coordinate, and pressure data of each stylus point as they are added to a stroke.

Run this sample

Public Sub New()
    MyBase.New()
    InitializeComponent()
    SetBoundary()
End Sub

'A new stroke object, MyStroke, is created and is added to the StrokeCollection object
'of the InkPresenter, MyIP
Private Sub MyIP_MouseLeftButtonDown(ByVal sender As Object, ByVal e As MouseEventArgs)
    MyIP.CaptureMouse()
    Dim MyStylusPointCollection As StylusPointCollection = New StylusPointCollection
    MyStylusPointCollection.Add(e.StylusDevice.GetStylusPoints(MyIP))
    MyStroke = New Stroke(MyStylusPointCollection)
    MyIP.Strokes.Add(MyStroke)
End Sub

'StylusPoint objects are collected from the MouseEventArgs and added to MyStroke
Private Sub MyIP_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
    If (Not (MyStroke) Is Nothing) Then
        MyStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(MyIP))
        XTB.Text = ("" + e.StylusDevice.GetStylusPoints(MyIP)(0).X)
        YTB.Text = ("" + e.StylusDevice.GetStylusPoints(MyIP)(0).Y)
        PressureTB.Text = ("" + e.StylusDevice.GetStylusPoints(MyIP)(0).PressureFactor)
    End If
End Sub

'MyStroke is completed
Private Sub MyIP_LostMouseCapture(ByVal sender As Object, ByVal e As MouseEventArgs)
    MyStroke = Nothing
End Sub

Private Sub SetBoundary()
    Dim MyRectangleGeometry As RectangleGeometry = New RectangleGeometry
    MyRectangleGeometry.Rect = New Rect(0, 0, MyIP.ActualHeight, MyIP.ActualWidth)
    MyIP.Clip = MyRectangleGeometry
End Sub
public Page()
{
    InitializeComponent();
    SetBoundary();
}

Stroke MyStroke;

//A new stroke object, MyStroke, is created and is added to the StrokeCollection object
//of the InkPresenter, MyIP
private void MyIP_MouseLeftButtonDown(object sender, MouseEventArgs e)
{
    MyIP.CaptureMouse();
    StylusPointCollection MyStylusPointCollection = new StylusPointCollection();
    MyStylusPointCollection.Add(e.StylusDevice.GetStylusPoints(MyIP));
    MyStroke = new Stroke(MyStylusPointCollection);

    MyIP.Strokes.Add(MyStroke);
}

//StylusPoint objects are collected from the MouseEventArgs and added to MyStroke
private void MyIP_MouseMove(object sender, MouseEventArgs e)
{
    if (MyStroke != null)
    {
        MyStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(MyIP));
        XTB.Text = "" + e.StylusDevice.GetStylusPoints(MyIP)[0].X;
        YTB.Text = "" + e.StylusDevice.GetStylusPoints(MyIP)[0].Y;
        PressureTB.Text = "" + e.StylusDevice.GetStylusPoints(MyIP)[0].PressureFactor;
    }
}

//MyStroke is completed
private void MyIP_LostMouseCapture(object sender, MouseEventArgs e)
{
    MyStroke = null;
}

private void SetBoundary()
{
    RectangleGeometry MyRectangleGeometry = new RectangleGeometry();
    MyRectangleGeometry.Rect = new Rect(0, 0, MyIP.ActualHeight, MyIP.ActualWidth);
    MyIP.Clip = MyRectangleGeometry;
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.