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樣。 這個範例假設有一textBox1個名為 TextBox 的 ,而且 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) ,並將 設定為 NoneCaptureMode

如果 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) ,並將 設定為 NoneCaptureMode

如果 element 看不到或啟用,方法會Capture(IInputElement, CaptureMode)false傳回 。

適用於