Mouse.Capture Mouse.Capture Mouse.Capture Mouse.Capture Method

定義

將滑鼠輸入捕捉至指定的項目。Captures mouse input to the specified element.

多載

Capture(IInputElement) Capture(IInputElement) Capture(IInputElement) Capture(IInputElement)

將滑鼠輸入捕捉至指定的項目。Captures mouse input to the specified element.

Capture(IInputElement, CaptureMode) Capture(IInputElement, CaptureMode) Capture(IInputElement, CaptureMode)

使用指定的 CaptureMode 將滑鼠輸入捕捉至指定項目。Captures mouse input to the specified element using the specified CaptureMode.

備註

當專案捕捉到滑鼠時, 不論游標是否在其框線內, 都會收到滑鼠輸入。When an element captures the mouse, it receives mouse input whether or not the cursor is within its borders.

如果未指定, 則預設值CaptureModeElementCaptureModeIf a CaptureMode is not specified, the default CaptureMode is Element.

若要釋放滑鼠捕捉, Capturenull呼叫傳遞做為要捕捉的元素。To release mouse capture, call Capture passing null as the element to capture.

如果在引發MouseDownMouseUp事件時捕捉到滑鼠, 而輸入不會進入滑鼠PreviewMouseUpOutsideCapturedElement底下的元素, PreviewMouseDownOutsideCapturedElement則會先引發。If the mouse is captured when a MouseDown or MouseUp event is raised and the input is not going to the element underneath the mouse, PreviewMouseDownOutsideCapturedElement and PreviewMouseUpOutsideCapturedElement are raised first. 這可讓已捕獲的元素有機會在MouseDownMouseUp事件路由之前釋放 capture。This enables the captured element a chance to release capture before the MouseDown and MouseUp events are routed.

Capture(IInputElement) Capture(IInputElement) Capture(IInputElement) Capture(IInputElement)

將滑鼠輸入捕捉至指定的項目。Captures mouse input 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 IInputElement IInputElement IInputElement

要捕捉滑鼠的項目。The element to capture the mouse.

傳回

如果項目可以捕捉滑鼠,則為 true;否則為 falsetrue if the element was able to capture the mouse; otherwise, false.

範例

下列範例示範如何使用Capture方法, 將滑鼠捕捉至特定專案。The following example shows how to capture the mouse to a specific element by using the Capture method.

private void OnCaptureMouseRequest(object sender, RoutedEventArgs e)
{
    Mouse.Capture(_elementToCapture);
}
Private Sub OnCaptureMouseRequest(ByVal sender As Object, ByVal e As RoutedEventArgs)
	Mouse.Capture(_elementToCapture)
End Sub

備註

當專案捕捉到滑鼠時, 不論游標是否在其框線內, 都會收到滑鼠輸入。When an element captures the mouse, it receives mouse input whether or not the cursor is within its borders.

如果未指定, 則預設值CaptureModeElementCaptureModeIf a CaptureMode is not specified, the default CaptureMode is Element.

若要釋放滑鼠捕捉, Capturenull呼叫傳遞做為要捕捉的元素。To release mouse capture, call Capture passing null as the element to capture.

如果在引發MouseDownMouseUp事件時捕捉到滑鼠, 而輸入不會進入滑鼠PreviewMouseUpOutsideCapturedElement底下的元素, PreviewMouseDownOutsideCapturedElement則會先引發。If the mouse is captured when a MouseDown or MouseUp event is raised and the input is not going to the element underneath the mouse, PreviewMouseDownOutsideCapturedElement and PreviewMouseUpOutsideCapturedElement are raised first. 這可讓已捕獲的元素有機會在MouseDownMouseUp事件路由之前釋放 capture。This enables the captured element a chance to release capture before the MouseDown and MouseUp events are routed.

Capture(IInputElement, CaptureMode) Capture(IInputElement, CaptureMode) Capture(IInputElement, CaptureMode)

使用指定的 CaptureMode 將滑鼠輸入捕捉至指定項目。Captures mouse input to the specified element using the specified 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

參數

element
IInputElement IInputElement IInputElement IInputElement

要捕捉滑鼠的項目。The element to capture the mouse.

captureMode
CaptureMode CaptureMode CaptureMode CaptureMode

要使用的捕捉原則。The capture policy to use.

傳回

如果項目可以捕捉滑鼠,則為 true;否則為 falsetrue if the element was able to capture the mouse; otherwise, false.

範例

下列範例示範如何使用Capture方法, 將滑鼠捕捉至特定專案。The following example shows how to capture the mouse to a specific element by using the Capture method.

private void OnCaptureMouseRequest(object sender, RoutedEventArgs e)
{
    Mouse.Capture(_elementToCapture);
}
Private Sub OnCaptureMouseRequest(ByVal sender As Object, ByVal e As RoutedEventArgs)
	Mouse.Capture(_elementToCapture)
End Sub

備註

當專案捕捉到滑鼠時, 不論游標是否在其框線內, 它都會接收滑鼠輸入。When an element captures the mouse, it receives mouse input whether the cursor is within its borders.

若要釋放滑鼠捕捉, Capturenull呼叫傳遞做為要捕捉的元素。To release mouse capture, call Capture passing null as the element to capture.

如果在引發MouseDownMouseUp事件時捕捉到滑鼠, 而輸入不會進入滑鼠PreviewMouseUpOutsideCapturedElement底下的元素, PreviewMouseDownOutsideCapturedElement則會先引發。If the mouse is captured when a MouseDown or MouseUp event is raised and the input is not going to the element underneath the mouse, PreviewMouseDownOutsideCapturedElement and PreviewMouseUpOutsideCapturedElement are raised first. 這可讓已捕獲的元素有機會在MouseDownMouseUp事件路由之前釋放 capture。This enables the captured element a chance to release capture before the MouseDown and MouseUp events are routed.

適用於