Mouse.Capture 方法

定义

将鼠标输入捕获到指定元素。Captures mouse input to the specified element.

重载

Capture(IInputElement)

将鼠标输入捕获到指定元素。Captures mouse input to the specified element.

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事件之前释放捕获。This enables the captured element a chance to release capture before the MouseDown and MouseUp events are routed.

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

要捕获鼠标的元素。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事件之前释放捕获。This enables the captured element a chance to release capture before the MouseDown and MouseUp events are routed.

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

要捕获鼠标的元素。The element to capture the mouse.

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事件之前释放捕获。This enables the captured element a chance to release capture before the MouseDown and MouseUp events are routed.

适用于