資訊
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

UIElement.ReleaseMouseCapture 方法

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

命名空間:  System.Windows
組件:  PresentationCore (在 PresentationCore.dll 中)

public void ReleaseMouseCapture()

實作

IInputElement.ReleaseMouseCapture()

如果這個項目未保有捕捉,呼叫這個方法便沒有作用。 請考慮在您呼叫這個方法前檢查 IsMouseCaptured 的值。

下列範例與針對 CaptureMouse 所提供的範例相似:它會處理滑鼠按鈕放開,以釋放滑鼠捕捉並重新啟用移動滑鼠。


private void MouseDownHandler(object sender, MouseButtonEventArgs e)
{
    if (!Enabled) return;
    e.Handled = true;


    if (Keyboard.IsKeyDown(Key.F1) == true)
    {
        Reset();
        return;
    }

    UIElement el = (UIElement)sender;
    _point = e.MouseDevice.GetPosition(el);
    // Initialize the center of rotation to the lookatpoint
    if (!_centered)
    {
        ProjectionCamera camera = (ProjectionCamera)_slaves[0].Camera;
        _center = camera.LookDirection;
        _centered = true;
    }

    _scaling = (e.MiddleButton == MouseButtonState.Pressed);

    if (Keyboard.IsKeyDown(Key.Space) == false)
        _rotating = true;
    else
        _rotating = false;

    el.CaptureMouse();
}

private void MouseUpHandler(object sender, MouseButtonEventArgs e)
{
    if (!_enabled) return;
    e.Handled = true;

    // Stuff the current initial + delta into initial so when we next move we
    // start at the right place.
    if (_rotating == true)
        _rotation = _rotationDelta * _rotation;
    else
    {
        _translate += _translateDelta;
        _translateDelta.X = 0;
        _translateDelta.Y = 0;
    }

    //_scale = _scaleDelta*_scale;
    UIElement el = (UIElement)sender;
    el.ReleaseMouseCapture();
}


.NET Framework

支援版本:4、3.5、3.0

.NET Framework Client Profile

支援版本:4、3.5 SP1

Windows 7, Windows Vista SP1 (含) 以後版本, Windows XP SP3, Windows Server 2008 (不支援伺服器核心), Windows Server 2008 R2 (SP1 (含) 以後版本支援伺服器核心), Windows Server 2003 SP2

.NET Framework 並不支援各種平台的所有版本。如需支援的版本的清單,請參閱.NET Framework 系統需求

社群新增項目

顯示:
© 2014 Microsoft