Redigera

Dela via


Stylus.Capture Method

Definition

Captures the stylus that is bound to a particular element.

Overloads

Capture(IInputElement)

Captures the stylus to the specified element.

Capture(IInputElement, CaptureMode)

Captures the stylus to the specified element.

Capture(IInputElement)

Captures the stylus to the specified element.

public:
 static bool Capture(System::Windows::IInputElement ^ element);
public static bool Capture (System.Windows.IInputElement element);
static member Capture : System.Windows.IInputElement -> bool
Public Shared Function Capture (element As IInputElement) As Boolean

Parameters

element
IInputElement

The element to capture the stylus to.

Returns

true if the stylus is captured to element; otherwise, false.

Examples

The following example demonstrates how to record the coordinates of the stylus, even if the stylus leaves the bounds of a TextBox. This example assumes there is a TextBox called textBox1, and that the StylusDown, StylusUp, and StylusMove events are connected to event handlers.

void textbox1_StylusDown(object sender, StylusDownEventArgs e)
{
    Stylus.Capture(textbox1);
}

void textbox1_StylusMove(object sender, StylusEventArgs e)
{
    Point pos = e.GetPosition(textbox1);
    textbox1.AppendText("X: " + pos.X + " Y: " + pos.Y + "\n");
}

void textbox1_StylusUp(object sender, StylusEventArgs e)
{
    Stylus.Capture(textbox1, CaptureMode.None);
}
Private Sub textbox1_StylusDown(ByVal sender As Object, ByVal e As System.Windows.Input.StylusDownEventArgs) _
    Handles textbox1.StylusDown

    Stylus.Capture(textbox1)

End Sub


Private Sub textbox1_StylusMove(ByVal sender As Object, ByVal e As StylusEventArgs) _
    Handles textbox1.StylusMove

    Dim pos As Point = e.GetPosition(textbox1)
    textbox1.AppendText("X: " & pos.X.ToString() & " Y: " & pos.Y.ToString() & vbLf)

End Sub


Private Sub textbox1_StylusUp(ByVal sender As Object, ByVal e As StylusEventArgs) _
    Handles textbox1.StylusUp

    Stylus.Capture(textbox1, CaptureMode.None)

End Sub

Remarks

Use the Capture(IInputElement) method to ensure that element receives stylus events even when the cursor goes out of the elements' bounds. To release the stylus, call Capture(IInputElement, CaptureMode) with the CaptureMode set to None.

The Capture(IInputElement) method returns false if element is not visible or enabled.

Applies to

Capture(IInputElement, CaptureMode)

Captures the stylus to the specified element.

public:
 static bool Capture(System::Windows::IInputElement ^ element, System::Windows::Input::CaptureMode captureMode);
public static bool Capture (System.Windows.IInputElement element, System.Windows.Input.CaptureMode captureMode);
static member Capture : System.Windows.IInputElement * System.Windows.Input.CaptureMode -> bool
Public Shared Function Capture (element As IInputElement, captureMode As CaptureMode) As Boolean

Parameters

element
IInputElement

The element to capture the stylus to.

captureMode
CaptureMode

One of the CaptureMode values.

Returns

true if the stylus is captured to element; otherwise, false.

Examples

The following example demonstrates how to record the coordinates of the stylus, even if the stylus leaves the bounds of a TextBox. This example assumes that there is a TextBox called textBox1, and that the StylusDown, StylusUp, and StylusMove events are connected to the event handlers.

void textbox1_StylusDown(object sender, StylusDownEventArgs e)
{
    Stylus.Capture(textbox1);
}

void textbox1_StylusMove(object sender, StylusEventArgs e)
{
    Point pos = e.GetPosition(textbox1);
    textbox1.AppendText("X: " + pos.X + " Y: " + pos.Y + "\n");
}

void textbox1_StylusUp(object sender, StylusEventArgs e)
{
    Stylus.Capture(textbox1, CaptureMode.None);
}
Private Sub textbox1_StylusDown(ByVal sender As Object, ByVal e As System.Windows.Input.StylusDownEventArgs) _
    Handles textbox1.StylusDown

    Stylus.Capture(textbox1)

End Sub


Private Sub textbox1_StylusMove(ByVal sender As Object, ByVal e As StylusEventArgs) _
    Handles textbox1.StylusMove

    Dim pos As Point = e.GetPosition(textbox1)
    textbox1.AppendText("X: " & pos.X.ToString() & " Y: " & pos.Y.ToString() & vbLf)

End Sub


Private Sub textbox1_StylusUp(ByVal sender As Object, ByVal e As StylusEventArgs) _
    Handles textbox1.StylusUp

    Stylus.Capture(textbox1, CaptureMode.None)

End Sub

Remarks

Use the Capture(IInputElement, CaptureMode) method to ensure that element receives stylus events even when the cursor goes out of the elements' bounds. To release the stylus, call Capture(IInputElement, CaptureMode) with the CaptureMode set to None.

The Capture(IInputElement, CaptureMode) method returns false if element is not visible or enabled.

Applies to