Stylus.Capture 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
捕捉綁定在特定元素上的觸控筆。
多載
| 名稱 | Description |
|---|---|
| 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
捕捉觸控筆的元素。
傳回
true若唱針被捕捉為element;否則,。 false
範例
以下範例示範如何記錄唱針的座標,即使唱針離開 的 TextBox範圍。 此範例假設存在被呼叫的 TextBox ,且 、 textBox1StylusDown與StylusUp事件都與事件處理程序相StylusMove連。
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。
如果 Capture(IInputElement) 未顯示或啟用,該false方法會回傳element。
適用於
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 價值。
傳回
true若唱針被捕捉為element;否則,。 false
範例
以下範例示範如何記錄唱針的座標,即使唱針離開 的 TextBox範圍。 此範例假設存在被呼叫的 TextBox ,且 textBox1、 StylusDown、 事件StylusUp與事件處理程序相StylusMove連。
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。
如果 Capture(IInputElement, CaptureMode) 未顯示或啟用,該false方法會回傳element。