Stylus.Capture 方法

定义

捕获绑定到特定元素的触笔。

重载

Capture(IInputElement)

捕获指定元素的触笔。

Capture(IInputElement, CaptureMode)

捕获指定元素的触笔。

Capture(IInputElement)

捕获指定元素的触笔。

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

要捕获触笔的元素。

返回

如果 element 捕获到触笔,则为 true;否则为 false

示例

以下示例演示如何记录触笔的坐标,即使触笔离开 的 TextBox边界也是如此。 此示例假定有一个名为 TextBoxtextBox1的 ,并且 StylusDownStylusUpStylusMove 事件已连接到事件处理程序。

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接收触笔事件,即使光标超出元素的边界也是如此。 若要释放触笔,请调用 Capture(IInputElement, CaptureMode) ,并将 CaptureMode 设置为 None

如果 element 不可见或未启用,则Capture(IInputElement)方法返回 false

适用于

Capture(IInputElement, CaptureMode)

捕获指定元素的触笔。

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

要捕获触笔的元素。

captureMode
CaptureMode

CaptureMode 值之一。

返回

如果 element 捕获到触笔,则为 true;否则为 false

示例

以下示例演示如何记录触笔的坐标,即使触笔离开 的 TextBox边界也是如此。 此示例假定有一个名为 TextBoxtextBox1的 ,并且 StylusDownStylusUpStylusMove 事件已连接到事件处理程序。

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接收触笔事件,即使光标超出元素的边界也是如此。 若要释放触笔,请调用 Capture(IInputElement, CaptureMode) ,并将 CaptureMode 设置为 None

如果 element 不可见或未启用,则Capture(IInputElement, CaptureMode)方法返回 false

适用于