Capture Method (IInputElement)
Collapse the table of content
Expand the table of content

Stylus.Capture Method (IInputElement)

Captures the stylus to the specified element.

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

public static bool Capture (
	IInputElement element
public static boolean Capture (
	IInputElement element
public static function Capture (
	element : IInputElement
) : boolean
You cannot use methods in XAML.



The element to capture the stylus to.

Return Value

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

Use the Capture(IInputElement) method to ensure that element receives stylus events even when the cursor goes out of bounds of element. 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.

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 the event handlers.

void textbox1_StylusDown(object sender, StylusDownEventArgs e)

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);

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

© 2016 Microsoft