Stylus.Capture 方法

定义

捕获绑定到特定元素的触笔。Captures the stylus that is bound to a particular element.

重载

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

参数

element
IInputElement

要捕获触笔的元素。The element to capture the stylus to.

返回

Boolean

如果 element 捕获到触笔,则为 true;否则为 falsetrue if the stylus is captured to element; otherwise, false.

示例

下面的示例演示如何记录触笔的坐标,即使触笔离开的边界也是如此 TextBoxThe following example demonstrates how to record the coordinates of the stylus, even if the stylus leaves the bounds of a TextBox. 此示例假设有一个被 TextBox 调用的 textBox1 ,并且 StylusDownStylusUp 和事件已 StylusMove 连接到事件处理程序。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

注解

使用 Capture(IInputElement) 方法可确保 element 即使光标超出元素的边界,也会接收触笔事件。Use the Capture(IInputElement) method to ensure that element receives stylus events even when the cursor goes out of the elements' bounds. 若要释放触笔,请调用, Capture(IInputElement, CaptureMode) 并将 CaptureMode 设置为 NoneTo release the stylus, call Capture(IInputElement, CaptureMode) with the CaptureMode set to None.

Capture(IInputElement) false 如果不 element 可见或未启用,则该方法返回。The Capture(IInputElement) method returns false if element is not visible or enabled.

适用于

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

参数

element
IInputElement

要捕获触笔的元素。The element to capture the stylus to.

captureMode
CaptureMode

CaptureMode 值之一。One of the CaptureMode values.

返回

Boolean

如果 element 捕获到触笔,则为 true;否则为 falsetrue if the stylus is captured to element; otherwise, false.

示例

下面的示例演示如何记录触笔的坐标,即使触笔离开的边界也是如此 TextBoxThe following example demonstrates how to record the coordinates of the stylus, even if the stylus leaves the bounds of a TextBox. 此示例假设有一个被 TextBox 调用的 textBox1 ,并且 StylusDownStylusUpStylusMove 事件已连接到事件处理程序。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

注解

使用 Capture(IInputElement, CaptureMode) 方法可确保 element 即使光标超出元素的边界,也会接收触笔事件。Use the Capture(IInputElement, CaptureMode) method to ensure that element receives stylus events even when the cursor goes out of the elements' bounds. 若要释放触笔,请调用, Capture(IInputElement, CaptureMode) 并将 CaptureMode 设置为 NoneTo release the stylus, call Capture(IInputElement, CaptureMode) with the CaptureMode set to None.

Capture(IInputElement, CaptureMode) false 如果不 element 可见或未启用,则该方法返回。The Capture(IInputElement, CaptureMode) method returns false if element is not visible or enabled.

适用于