ContentElement.ReleaseMouseCapture Metoda

Definicja

Zwalnia przechwytywanie myszy, jeśli ten element trzymał przechwytywanie.

public:
 virtual void ReleaseMouseCapture();
public void ReleaseMouseCapture ();
abstract member ReleaseMouseCapture : unit -> unit
override this.ReleaseMouseCapture : unit -> unit
Public Sub ReleaseMouseCapture ()

Implementuje

Przykłady

Poniższa procedura obsługi przechwytuje lub zwalnia przechwytywanie myszy zgodnie ze stanami przycisku myszy. W przykładzie pokazano, jak używać przechwyconego ruchu myszy do alternatywnych celów innych niż przenoszenie wskaźnika myszy w interfejsie użytkownika.

private void MouseDownHandler(object sender, MouseButtonEventArgs e)
{
    ContentElement el = (ContentElement)sender;
    if (!el.IsEnabled) return;
    e.Handled = true;
    el.CaptureMouse();
    _point = e.MouseDevice.GetPosition(el); 
}

private void MouseUpHandler(object sender, MouseButtonEventArgs e)
{
    ContentElement el = (ContentElement)sender;
    if (!el.IsEnabled) return;
    e.Handled = true;
    el.ReleaseMouseCapture();
}
Private Sub MouseDownHandler(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
    Dim el As ContentElement = CType(sender, ContentElement)
    If Not el.IsEnabled Then
        Return
    End If
    e.Handled = True
    el.CaptureMouse()
    _point = e.MouseDevice.GetPosition(el)
End Sub

Private Sub MouseUpHandler(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
    Dim el As ContentElement = CType(sender, ContentElement)
    If Not el.IsEnabled Then
        Return
    End If
    e.Handled = True
    el.ReleaseMouseCapture()
End Sub

Uwagi

Jeśli ten element nie trzymał przechwytywania, wywołanie tej metody nie ma wpływu. Rozważ sprawdzenie wartości przed IsMouseCaptured wywołaniem tej metody.

Dotyczy

Zobacz też