Condividi tramite


ReleaseMouseCapture

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Disables mouse capture for the object.

object.ReleaseMouseCapture()

Managed Equivalent

ReleaseMouseCapture

Remarks

The ReleaseMouseCapture method disables mouse capture for a plug-in that has captured the mouse by using the CaptureMouse method. When a plug-in instance has captured the mouse, it receives mouse input regardless of whether the cursor is within its borders. The mouse is typically captured only during drag operations.

For more information on basic concepts, see Mouse Support. Note that the Mouse Support topic is written primarily for users of the managed API, and may not have code examples or specific information that address the JavaScript API scenarios.

Example

The following JavaScript example shows the mouse being captured and released by using event handler functions for the MouseLeftButtonDown and MouseLeftButtonUp events.

// Display the current mouse position for the Rectangle object.
function onMouseMove(sender, mouseEventArgs)
{
    var msg = "x:y = " + mouseEventArgs.getPosition(null).x + ", " + mouseEventArgs.getPosition(null).y;
    sender.findName("statusTextBlock").Text = sender.Name + ": " + msg;
}

// Enable mouse capture when the mouse button is pressed over the green Rectangle object.
function onLeftButtonDown(greenRect, mouseEventArgs) 
{
    greenRect.captureMouse();
}

// Disable mouse capture when the mouse button is released over the green Rectangle object.
function onLeftButtonUp(greenRect, mouseEventArgs) 
{
    greenRect.releaseMouseCapture();
}

Applies To

Border (Silverlight 2)

Canvas

Ellipse

Glyphs

Image

InkPresenter

Line

MediaElement

PasswordBox (Silverlight 2)

Path

Polygon

Polyline

Popup (Silverlight 2)

Rectangle

StackPanel (Silverlight 2)

TextBlock

TextBox (Silverlight 2)