Επεξεργασία

Κοινή χρήση μέσω


Mouse.Capture Method

Definition

Captures mouse input to the specified element.

Overloads

Capture(IInputElement)

Captures mouse input to the specified element.

Capture(IInputElement, CaptureMode)

Captures mouse input to the specified element using the specified CaptureMode.

Remarks

When an element captures the mouse, it receives mouse input whether or not the cursor is within its borders.

If a CaptureMode is not specified, the default CaptureMode is Element.

To release mouse capture, call Capture passing null as the element to capture.

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. 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

Parameters

element
IInputElement

The element to capture the mouse.

Returns

true if the element was able to capture the mouse; otherwise, false.

Examples

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

Remarks

When an element captures the mouse, it receives mouse input whether or not the cursor is within its borders.

If a CaptureMode is not specified, the default CaptureMode is Element.

To release mouse capture, call Capture passing null as the element to capture.

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. This enables the captured element a chance to release capture before the MouseDown and MouseUp events are routed.

Applies to

Capture(IInputElement, 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
Public Shared Function Capture (element As IInputElement, captureMode As CaptureMode) As Boolean

Parameters

element
IInputElement

The element to capture the mouse.

captureMode
CaptureMode

The capture policy to use.

Returns

true if the element was able to capture the mouse; otherwise, false.

Examples

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

Remarks

When an element captures the mouse, it receives mouse input whether the cursor is within its borders.

To release mouse capture, call Capture passing null as the element to capture.

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. This enables the captured element a chance to release capture before the MouseDown and MouseUp events are routed.

Applies to