当前位置: 首页>>代码示例>>C#>>正文


C# FrameworkElement.ReleaseMouseCapture方法代码示例

本文整理汇总了C#中System.Windows.FrameworkElement.ReleaseMouseCapture方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElement.ReleaseMouseCapture方法的具体用法?C# FrameworkElement.ReleaseMouseCapture怎么用?C# FrameworkElement.ReleaseMouseCapture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.FrameworkElement的用法示例。


在下文中一共展示了FrameworkElement.ReleaseMouseCapture方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnApplyTemplate

        public override void OnApplyTemplate()
        {
            PART_SBPicker = (FrameworkElement)GetTemplateChild("PART_SBPicker");
            PART_SBHost = (FrameworkElement)GetTemplateChild("PART_SBHost");

            PART_SBHost.PreviewMouseLeftButtonDown += delegate(object s, MouseButtonEventArgs e) { PART_SBHost.CaptureMouse(); CalculateSB(e); };
            PART_SBHost.PreviewMouseLeftButtonUp += (s, e) => PART_SBHost.ReleaseMouseCapture();
            PART_SBHost.PreviewMouseMove += (s, e) => CalculateSB(e);

            PART_HuePicker = (FrameworkElement)GetTemplateChild("PART_HuePicker");
            PART_HueHost = (FrameworkElement)GetTemplateChild("PART_HueHost");

            PART_HueHost.PreviewMouseLeftButtonDown += delegate(object s, MouseButtonEventArgs e) { PART_HueHost.CaptureMouse(); CalculateHue(e); };
            PART_HueHost.PreviewMouseLeftButtonUp += (s, e) => PART_HueHost.ReleaseMouseCapture();
            PART_HueHost.PreviewMouseMove += (s, e) => CalculateHue(e);

            base.OnApplyTemplate();
        }
开发者ID:KimDongWan,项目名称:Miseng,代码行数:18,代码来源:BorderColorPicker.xaml.cs

示例2: ProcessKey

        public void ProcessKey(FrameworkElement uie, KeyEventArgs e)
        {
            bool Alt = (Keyboard.Modifiers & ModifierKeys.Alt) != 0;
             bool Control = (Keyboard.Modifiers & ModifierKeys.Control) != 0;
             bool Shift = (Keyboard.Modifiers & ModifierKeys.Shift) != 0;

             if (uie.IsMouseCaptured)
            uie.ReleaseMouseCapture();

             //TODO: Might be able to remove this: http://www.ageektrapped.com/blog/using-commands-in-babysmash/
             if (Alt && Control && Shift && e.Key == Key.O)
             {
            ShowOptionsDialog();
            e.Handled = true;
            return;
             }

             string s = e.Key.ToString();
             if (s.Length == 2 && s[0] == 'D') s = s[1].ToString(); //HACK: WTF? Numbers start with a "D?" as in D1?
             AddFigure(uie, s);
        }
开发者ID:goldman99,项目名称:SnoopBreadcrumbs,代码行数:21,代码来源:Controller.cs

示例3: SetResize

        public void SetResize(FrameworkElement _resize) {
            var start = new Point();

            _resize.SetBinding(VisibilityProperty,
                new Binding {
                    Source = _fe,
                    Path = new PropertyPath("CanScale"),
                    Converter = new BooleanToVisibilityConverter()
                });

            _resize.MouseDown += (e, s) => {
                start = s.GetPosition(_svi);
                s.Handled = true;
                s.MouseDevice.Capture(_resize);
            };
            _resize.MouseMove += (e, s) => {
                if (s.LeftButton == MouseButtonState.Pressed) {
                    var p = s.GetPosition(_svi);
                    var difx = p.X - start.X;
                    var dify = p.Y - start.Y;
                    var nw = _svi.ActualWidth + difx;
                    if (nw > _fe.SwitchWidth) _svi.Width = nw;
                    _svi.Height = _svi.ActualHeight + dify;
                    start = p;
                    s.Handled = true;
                }
            };
            _resize.MouseUp += (e, s) => _resize.ReleaseMouseCapture();

            _resize.TouchDown += (e, s) => {
                start = s.GetTouchPoint(_svi).Position;
                s.Handled = true;
                s.TouchDevice.Capture(_resize);
            };

            _resize.TouchMove += (e, s) => {
                var p = s.GetTouchPoint(_svi).Position;
                var difx = p.X - start.X;
                var dify = p.Y - start.Y;
                var nw = _svi.ActualWidth + difx;
                if (nw > _fe.SwitchWidth) _svi.Width = nw;
                _svi.Height = _svi.ActualHeight + dify;
                start = p;
                s.Handled = true;
            };
        }
开发者ID:TNOCS,项目名称:csTouch,代码行数:46,代码来源:FloatingContainer.cs

示例4: OnDragEnd

        internal void OnDragEnd(FrameworkElement child, Point origin, Point position)
        {
            if (child == null)
                return;

            Dispatcher.Invoke(() =>
            {
                // Remove empty pages
                for (int i = pages.Count - 1; i >= 0; i--)
                {
                    if (pages[i].Count == 0)
                        pages.RemoveAt(i);
                }

                // Reset opacity
                child.Opacity = DefaultOpacity;
                child.SetValue(ZIndexProperty, TransitionZ);
                child.ReleaseMouseCapture();

                dragging = null;

                UpdateFluidLayout(true);
            });
        }
开发者ID:jluchiji,项目名称:launcher-panel,代码行数:24,代码来源:PanoramaPanel.cs

示例5: AddMoblieBodyMouseAction

 /// <summary>
 /// 添加右键对单元移动
 /// </summary>
 /// <param name="body">移动单元</param>
 /// <param name="element">移动单元所在的容器</param>
 void AddMoblieBodyMouseAction(FrameworkElement body, FrameworkElement element)
 {
     MouseButtonEventHandler rightButtonDown = null;
     MouseEventHandler mouseMove = null;
     MouseButtonEventHandler rightButtonUp = null;
     Point ptDown = new Point();
     Point ptMove = new Point();
     Panel parentCanvas = (body.Parent as Panel);
     rightButtonDown = (s, e) =>
     {
         body.MouseRightButtonDown -= rightButtonDown;
         body.MouseRightButtonUp += rightButtonUp;
         body.MouseMove += mouseMove;
         ptDown = e.GetPosition(body);
         body.CaptureMouse();
         BringUIElementTop(body);
     };
     mouseMove = (s, e) =>
     {
         ptMove = e.GetPosition(element);
         //显示当前单元在容器中的位置
         Point currentPoint = new Point(ptMove.X - ptDown.X, ptMove.Y - ptDown.Y);
         Canvas.SetLeft(body, currentPoint.X);
         Canvas.SetTop(body, currentPoint.Y);
         //Point releativePoint = parentCanvas.TranslatePoint(currentPoint, BackgroundCanvasA);
         //debugText.Text = string.Format("({0},{1})", Math.Round(releativePoint.X), Math.Round(releativePoint.Y));
     };
     rightButtonUp = (s, e) =>
     {
         body.MouseRightButtonDown += rightButtonDown;
         body.MouseRightButtonUp -= rightButtonUp;
         body.MouseMove -= mouseMove;
         body.ReleaseMouseCapture();
     };
     body.MouseRightButtonDown += rightButtonDown;
 }
开发者ID:jiailiuyan,项目名称:Jisons,代码行数:41,代码来源:Global.cs

示例6: RegisterBorderEvents


//.........这里部分代码省略.........
                            break;
                        case WindowBorderEdge.BottomRight:
                            cursorOffset.X = (Width - cursorLocation.X);
                            cursorOffset.Y = (Height - cursorLocation.Y);
                            break;
                        case WindowBorderEdge.Bottom:
                            cursorOffset.Y = (Height - cursorLocation.Y);
                            break;
                        case WindowBorderEdge.BottomLeft:
                            cursorOffset.X = cursorLocation.X;
                            cursorOffset.Y = (Height - cursorLocation.Y);
                            break;
                    }

                    this.cursorOffset = cursorOffset;

                    border.CaptureMouse();
                }
            };

            border.MouseMove += (sender, e) =>
            {
                if (WindowState != WindowState.Maximized && border.IsMouseCaptured && ResizeMode == ResizeMode.CanResize)
                {
                    Point cursorLocation = e.GetPosition(this);

                    double nHorizontalChange = (cursorLocation.X - cursorOffset.X);
                    double pHorizontalChange = (cursorLocation.X + cursorOffset.X);
                    double nVerticalChange = (cursorLocation.Y - cursorOffset.Y);
                    double pVerticalChange = (cursorLocation.Y + cursorOffset.Y);

                    switch (borderEdge)
                    {
                        case WindowBorderEdge.Left:
                            if (Width - nHorizontalChange <= MinWidth)
                                break;
                            Left += nHorizontalChange;
                            Width -= nHorizontalChange;
                            break;
                        case WindowBorderEdge.TopLeft:
                            if (Width - nHorizontalChange <= MinWidth)
                                break;
                            Left += nHorizontalChange;
                            Width -= nHorizontalChange;
                            if (Height - nVerticalChange <= MinHeight)
                                break;
                            Top += nVerticalChange;
                            Height -= nVerticalChange;
                            break;
                        case WindowBorderEdge.Top:
                            if (Height - nVerticalChange <= MinHeight)
                                break;
                            Top += nVerticalChange;
                            Height -= nVerticalChange;
                            break;
                        case WindowBorderEdge.TopRight:
                            if (pHorizontalChange <= MinWidth)
                                break;
                            Width = pHorizontalChange;
                            if (Height - nVerticalChange <= MinHeight)
                                break;
                            Top += nVerticalChange;
                            Height -= nVerticalChange;
                            break;
                        case WindowBorderEdge.Right:
                            if (pHorizontalChange <= MinWidth)
                                break;
                            Width = pHorizontalChange;
                            break;
                        case WindowBorderEdge.BottomRight:
                            if (pHorizontalChange <= MinWidth)
                                break;
                            Width = pHorizontalChange;
                            if (pVerticalChange <= MinHeight)
                                break;
                            Height = pVerticalChange;
                            break;
                        case WindowBorderEdge.Bottom:
                            if (pVerticalChange <= MinHeight)
                                break;
                            Height = pVerticalChange;
                            break;
                        case WindowBorderEdge.BottomLeft:
                            if (Width - nHorizontalChange <= MinWidth)
                                break;
                            Left += nHorizontalChange;
                            Width -= nHorizontalChange;
                            if (pVerticalChange <= MinHeight)
                                break;
                            Height = pVerticalChange;
                            break;
                    }
                }
            };

            border.MouseLeftButtonUp += (sender, e) =>
            {
                border.ReleaseMouseCapture();
            };
        }
开发者ID:DimaLupyak,项目名称:WpfSorter,代码行数:101,代码来源:ThemedWindow.cs

示例7: MakeDraggable

        /// <summary>
        /// The actual method to make the FrameworkElement Draggable
        /// </summary>
        /// <param name="element">The element who.</param>
        /// <param name="elementParent">The element parent.</param>
        /// <param name="status">The status.</param>
        private static void MakeDraggable(
            FrameworkElement element,
            Panel elementParent,
            TextBlock status)
        {
            if (IsDraggableType(element))
            {
                if (IsDraggableType(element))
                {
                    // If this element already has a DragInfo associated with it then
                    // enable the IsDraggable and return.
                    var di = (((element as FrameworkElement).Parent as Canvas).Tag as DragInfo);

                    di.IsDraggable = true;

                    return;
                }
            }

            var canvasWrapper = new Canvas
                                    {
                                        Background = new SolidColorBrush(Colors.Transparent),
                                    };

            elementParent.Children.Remove(element);

            canvasWrapper.Tag = new DragInfo(); // Keep a DragInfo instance in FrameworkElement.Tag for further reference

            canvasWrapper.Children.Add(element);

            elementParent.Children.Add(canvasWrapper);

            // Attach to the MouseLeftButtonDown event.
            element.MouseLeftButtonDown += (o,
                                            e) =>
                                               {
                                                   var dragInfo = canvasWrapper.Tag as DragInfo;
                                                   if (dragInfo != null)
                                                   {
                                                       // Check if we can drag
                                                       if (dragInfo.IsDraggable)
                                                       {
                                                           // Mark that we're doing a drag
                                                           dragInfo.IsDragging = true;

                                                           // Ensure that the mouse can't leave element being dragged
                                                           element.CaptureMouse();

                                                           // Determine where the mouse 'grabbed'
                                                           // to use during MouseMove
                                                           dragInfo.Offset = e.GetPosition(element);
                                                       }
                                                   }
                                               };

            // Attach to the MouseLeftButtonUp event.
            element.MouseLeftButtonUp += (o,
                                          e) =>
                                             {
                                                 var dragInfo = canvasWrapper.Tag as DragInfo;
                                                 if (dragInfo != null)
                                                 {
                                                     // Check if we can drag
                                                     if (dragInfo.IsDraggable)
                                                     {
                                                         if (dragInfo.IsDragging)
                                                         {
                                                             // Turn off Dragging
                                                             dragInfo.IsDragging = false;

                                                             // Free the Mouse
                                                             element.ReleaseMouseCapture();
                                                         }
                                                     }
                                                 }
                                             };

            // Attach to the MouseMove event.
            element.MouseMove += (o,
                                  e) =>
                                     {
                                         var dragInfo = canvasWrapper.Tag as DragInfo;
                                         if (dragInfo != null)
                                         {
                                             // Check if we can drag
                                             if (dragInfo.IsDraggable)
                                             {
                                                 if (dragInfo.IsDragging)
                                                 {
                                                     // Where is the mouse now?
                                                     Point newPosition = e.GetPosition(canvasWrapper);

                                                     if (status != null)
                                                     {
//.........这里部分代码省略.........
开发者ID:Titaye,项目名称:SLExtensions,代码行数:101,代码来源:DraggableExtensions.cs

示例8: ProcessKey

        public void ProcessKey(FrameworkElement uie, KeyEventArgs e)
        {
            bool Alt = (Keyboard.Modifiers & ModifierKeys.Alt) != 0;
            bool Control = (Keyboard.Modifiers & ModifierKeys.Control) != 0;
            bool Shift = (Keyboard.Modifiers & ModifierKeys.Shift) != 0;

            if (uie.IsMouseCaptured)
            {
                uie.ReleaseMouseCapture();
            }

            //TODO: Might be able to remove this: http://www.ageektrapped.com/blog/using-commands-in-babysmash/
            if (Alt && Control && Shift && e.Key == Key.O)
            {
                ShowOptionsDialog();
                e.Handled = true;
                return;
            }

            char displayChar = GetDisplayChar(e.Key);
            AddFigure(uie, displayChar);
        }
开发者ID:rmarinho,项目名称:babysmash,代码行数:22,代码来源:Controller.cs

示例9: WireUIElementForDragAndDrop

        private void WireUIElementForDragAndDrop(FrameworkElement target, Func<Rect, bool> isInBounds)
        {
            Point origin = default(Point);

            var mouseDown = Observable.FromEventPattern<MouseButtonEventArgs>(target, "MouseDown");
            mouseDown.Subscribe(p =>
            {
                target.CaptureMouse();
                origin = p.EventArgs.GetPosition(target);
            });

            var mouseUp = Observable.FromEventPattern<MouseButtonEventArgs>(target, "MouseUp")
                .Publish();

            var mouseLeave = Observable.FromEventPattern<MouseEventArgs>(target, "MouseLeave")
                .Publish();

            //hot observables
            mouseUp.Connect();
            mouseLeave.Connect();

            var mouseMove = Observable.FromEventPattern<MouseEventArgs>(target, "MouseMove");
            //var mouseHitTest = Observable.Create(mouseMove =>
            //    {
            //        return Task.Factory.StartNew<Action>(p => { return true; });
            //    });

            var mouseUpOrLeave = Observable.CombineLatest(mouseUp, mouseLeave, (a, b) => { return true; });
            mouseUpOrLeave
                .Do(_ => Console.WriteLine("MouseUpOrLeave fired {0}", Guid.NewGuid()))
                .Subscribe(p => { target.ReleaseMouseCapture(); });

            mouseMove
                .Select(x => x.EventArgs.GetPosition(target))
                .SkipUntil(mouseDown).Repeat()
                .TakeUntil(mouseUpOrLeave).Repeat()
                .Subscribe(p=> {
                    var dX = p.X - origin.X;
                    var dY = p.Y - origin.Y;
                    var moveTo = new Point(Canvas.GetLeft(target)+ dX, Canvas.GetTop(target)+ dY);
                    if (isInBounds(new Rect(moveTo, new Point(moveTo.X + target.ActualWidth, moveTo.Y + target.ActualHeight))))
                    {
                        Canvas.SetTop(target, moveTo.Y);
                        Canvas.SetLeft(target, moveTo.X);
                    }
                });
        }
开发者ID:pdoh00,项目名称:Sandbox,代码行数:47,代码来源:MainWindow.xaml.cs

示例10: MouseLeftButtonUpMethod

        private void MouseLeftButtonUpMethod(FrameworkElement element)
        {
            element.ReleaseMouseCapture();
            isMouseCaptured = false;

            double scale = 1;
            if (element.IsActivity())
            {
                scale = ((ScaleResizingAdorner)elements[element]).Scale;
            }

            OnWidgetDragging(element, new WidgetDraggingEventArgs(new Point(
                Canvas.GetLeft(element) + element.ActualWidth * scale, Canvas.GetTop(element) + element.ActualHeight * scale)));
        }
开发者ID:barbarossia,项目名称:CWF,代码行数:14,代码来源:DraggingWidgetHelper.cs

示例11: RegisterBorderEvents


//.........这里部分代码省略.........
                        break;
                    case DirectionOfResize.BottomRight:
                        cursorOffset.X = (window.Width - cursorLocation.X);
                        cursorOffset.Y = (window.Height - cursorLocation.Y);
                        break;
                    case DirectionOfResize.Bottom:
                        cursorOffset.Y = (window.Height - cursorLocation.Y);
                        break;
                    case DirectionOfResize.BottomLeft:
                        cursorOffset.X = cursorLocation.X;
                        cursorOffset.Y = (window.Height - cursorLocation.Y);
                        break;
                }

                this.cursorOffset = cursorOffset;

                border.CaptureMouse();
            };

            border.MouseMove += (sender, e) =>
            {
                if (border.IsMouseCaptured)
                {
                    window.SizeToContent = SizeToContent.Manual;
                    Point cursorLocation = e.GetPosition(window);

                    double nHorizontalChange = (cursorLocation.X - cursorOffset.X);
                    double pHorizontalChange = (cursorLocation.X + cursorOffset.X);
                    double nVerticalChange = (cursorLocation.Y - cursorOffset.Y);
                    double pVerticalChange = (cursorLocation.Y + cursorOffset.Y);

                    switch (DirectionOfResize)
                    {
                        case DirectionOfResize.Left:
                            if (window.Width - nHorizontalChange <= window.MinWidth)
                                break;
                            window.Left += nHorizontalChange;
                            window.Width -= nHorizontalChange;
                            break;
                        case DirectionOfResize.TopLeft:
                            if (window.Width - nHorizontalChange <= window.MinWidth)
                                break;
                            window.Left += nHorizontalChange;
                            window.Width -= nHorizontalChange;
                            if (window.Height - nVerticalChange <= window.MinHeight)
                                break;
                            window.Top += nVerticalChange;
                            window.Height -= nVerticalChange;
                            break;
                        case DirectionOfResize.Top:
                            if (window.Height - nVerticalChange <= window.MinHeight)
                                break;
                            window.Top += nVerticalChange;
                            window.Height -= nVerticalChange;
                            break;
                        case DirectionOfResize.TopRight:
                            if (pHorizontalChange <= window.MinWidth)
                                break;
                            window.Width = pHorizontalChange;
                            if (window.Height - nVerticalChange <= window.MinHeight)
                                break;
                            window.Top += nVerticalChange;
                            window.Height -= nVerticalChange;
                            break;
                        case DirectionOfResize.Right:
                            if (pHorizontalChange <= window.MinWidth)
                                break;
                            window.Width = pHorizontalChange;
                            break;
                        case DirectionOfResize.BottomRight:
                            if (pHorizontalChange <= window.MinWidth)
                                break;
                            window.Width = pHorizontalChange;
                            if (pVerticalChange <= window.MinHeight)
                                break;
                            window.Height = pVerticalChange;
                            break;
                        case DirectionOfResize.Bottom:
                            if (pVerticalChange <= window.MinHeight)
                                break;
                            window.Height = pVerticalChange;
                            break;
                        case DirectionOfResize.BottomLeft:
                            if (window.Width - nHorizontalChange <= window.MinWidth)
                                break;
                            window.Left += nHorizontalChange;
                            window.Width -= nHorizontalChange;
                            if (pVerticalChange <= window.MinHeight)
                                break;
                            window.Height = pVerticalChange;
                            break;
                    }
                }
            };

            border.MouseLeftButtonUp += (sender, e) =>
            {
                border.ReleaseMouseCapture();
            };
        }
开发者ID:KiselevKN,项目名称:BootMega,代码行数:101,代码来源:WindowChrome.cs

示例12: TouchListener

        public TouchListener(FrameworkElement element)
        {
            _multitouchtuio = new MIG.Client.Devices.MultiTouch.MultitouchTuio();

            _propagateinput = true;
            _targetelement = element;

            (_targetelement as Panel).Children.Add(_infolayer);
            _cursors = new List<MIG.Client.Devices.MultiTouch.Cursor>();

            _targetelement.Dispatcher.BeginInvoke(() =>
            {
                _targetsize = new Size(_targetelement.ActualWidth, _targetelement.ActualHeight);
                //
                // Standard Mouse Input mapped to touch
                //
                _targetelement.MouseLeftButtonDown += new MouseButtonEventHandler(delegate(object o, MouseButtonEventArgs e) { _targetelement.CaptureMouse(); MouseCursorAdd(e); });
                _targetelement.MouseLeftButtonUp += new MouseButtonEventHandler(delegate { MouseCursorDel(); _targetelement.ReleaseMouseCapture(); });
                _targetelement.MouseMove += new MouseEventHandler(delegate(object o, MouseEventArgs e) { MouseCursorSet(e); });
                //
                // Multitouch TUIO input
                //
                _multitouchtuio.FingerDown += new MIG.Client.Devices.MultiTouch.MultitouchTuio.FingerDownHandler(MultiTouchListener_FingerDown);
                _multitouchtuio.FingerUp += new MIG.Client.Devices.MultiTouch.MultitouchTuio.FingerUpHandler(MultiTouchListener_FingerUp);
                _multitouchtuio.FingerMove += new MIG.Client.Devices.MultiTouch.MultitouchTuio.FingerMoveHandler(MultiTouchListener_FingerMove);
                _multitouchtuio.AccelerationUpdate += new MIG.Client.Devices.MultiTouch.MultitouchTuio.AccelerationUpdateHandler(MultiTouchListener_AccelerationUpdate);
                //
                // Windows 7 WM_TOUCH events fw
                //
                Touch.FrameReported += new TouchFrameEventHandler(Touch_FrameReported);
            });
        }
开发者ID:sugasaki,项目名称:Kinect,代码行数:32,代码来源:TouchListener.cs


注:本文中的System.Windows.FrameworkElement.ReleaseMouseCapture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。