Redigera

Dela via


MouseDevice.Capture Method

Definition

Captures mouse input to the specified element.

Overloads

Capture(IInputElement)

Captures mouse events 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 events to the specified element.

public:
 bool Capture(System::Windows::IInputElement ^ element);
public bool Capture (System.Windows.IInputElement element);
member this.Capture : System.Windows.IInputElement -> bool
Public 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.

Exceptions

Remarks

When an element captures the mouse, it receives mouse input whether 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:
 bool Capture(System::Windows::IInputElement ^ element, System::Windows::Input::CaptureMode captureMode);
[System.Security.SecurityCritical]
public bool Capture (System.Windows.IInputElement element, System.Windows.Input.CaptureMode captureMode);
public bool Capture (System.Windows.IInputElement element, System.Windows.Input.CaptureMode captureMode);
[<System.Security.SecurityCritical>]
member this.Capture : System.Windows.IInputElement * System.Windows.Input.CaptureMode -> bool
member this.Capture : System.Windows.IInputElement * System.Windows.Input.CaptureMode -> bool
Public 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.

Attributes

Exceptions

captureMode is not a valid CaptureMode.

Remarks

When an element captures the mouse, it receives mouse input whether or not 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