共用方式為


ContentElement.ReleaseMouseCapture 方法

定義

如果這個項目保有滑鼠捕捉,則釋放捕捉。

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

實作

範例

下列處理常式會根據滑鼠按鍵狀態擷取或釋放滑鼠擷取。 此範例示範如何使用擷取的滑鼠移動做為 UI 中移動滑鼠指標以外的替代用途。

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

備註

如果這個專案未保存擷取,則呼叫這個方法沒有任何作用。 請考慮在呼叫這個方法之前檢查 的值 IsMouseCaptured

適用於

另請參閱