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.

C#
public static bool Capture(System.Windows.IInputElement element);

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.

C#
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);
}

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Capture(IInputElement, CaptureMode)

Captures the stylus to the specified element.

C#
public static bool Capture(System.Windows.IInputElement element, System.Windows.Input.CaptureMode captureMode);

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.

C#
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);
}

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9