本文由机器翻译。若要查看英语原文,请勾选“英语”复选框。 也可将鼠标指针移到文本上,在弹出窗口中显示英语原文。
翻译
英语

UIElement.ReleaseMouseCapture 方法 ()

 

如果此元素保留在捕获鼠标捕获,则释放。

命名空间:   System.Windows
程序集:  PresentationCore(位于 PresentationCore.dll)

public void 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
自 3.0 起可用
Silverlight
自 2.0 起可用
Windows Phone Silverlight
自 7.0 起可用
返回页首
显示: