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


C# FrameworkElement.CaptureMouse方法代码示例

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


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

示例1: 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

示例2: 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

示例3: Grip_MouseLeftButtonDown

        private void Grip_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ClickCount == 1)
            {
                frameworkElement = (FrameworkElement)sender;

                startDragPoint = frameworkElement.PointToScreen(Mouse.GetPosition(frameworkElement));
                originalWidth = ActualWidth;
                originalHeight = ActualHeight;
                frameworkElement.CaptureMouse();
                e.Handled = true;
            }
        }
开发者ID:rburda82,项目名称:proxysearcher,代码行数:13,代码来源:ResizeControl.xaml.cs

示例4: OnDragStart

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

            Dispatcher.Invoke(() =>
            {
                child.Opacity = DragOpacity;
                child.SetValue(ZIndexProperty, DragZ);
                // Dragging point within the moving element
                dragStart = new Point(origin.X * DragScale, origin.Y * DragScale);
                // Apply transform without moving the element
                Point translatePosition = child.TranslatePoint(new Point(-child.Margin.Left, -child.Margin.Top), this);
                child.RenderTransform = CreateTransform(translatePosition.X, translatePosition.Y, DragScale, DragScale);
                // Capture further mouse events
                child.CaptureMouse();
                // Record the initial position of the element
                dragSourcePage = GetPageIndex(position);
                dragSourceCell = GetCellIndex(position);
                //
                dragging = child;
            });
        }
开发者ID:jluchiji,项目名称:launcher-panel,代码行数:23,代码来源: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

        private void RegisterBorderEvents(WindowBorderEdge borderEdge, FrameworkElement border)
        {
            border.MouseEnter += (sender, e) =>
            {
                if (WindowState != WindowState.Maximized && ResizeMode == ResizeMode.CanResize)
                {
                    switch (borderEdge)
                    {
                        case WindowBorderEdge.Left:
                        case WindowBorderEdge.Right:
                            border.Cursor = Cursors.SizeWE;
                            break;
                        case WindowBorderEdge.Top:
                        case WindowBorderEdge.Bottom:
                            border.Cursor = Cursors.SizeNS;
                            break;
                        case WindowBorderEdge.TopLeft:
                        case WindowBorderEdge.BottomRight:
                            border.Cursor = Cursors.SizeNWSE;
                            break;
                        case WindowBorderEdge.TopRight:
                        case WindowBorderEdge.BottomLeft:
                            border.Cursor = Cursors.SizeNESW;
                            break;
                    }
                }
                else
                {
                    border.Cursor = Cursors.Arrow;
                }
            };

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

                    switch (borderEdge)
                    {
                        case WindowBorderEdge.Left:
                            cursorOffset.X = cursorLocation.X;
                            break;
                        case WindowBorderEdge.TopLeft:
                            cursorOffset.X = cursorLocation.X;
                            cursorOffset.Y = cursorLocation.Y;
                            break;
                        case WindowBorderEdge.Top:
                            cursorOffset.Y = cursorLocation.Y;
                            break;
                        case WindowBorderEdge.TopRight:
                            cursorOffset.X = (Width - cursorLocation.X);
                            cursorOffset.Y = cursorLocation.Y;
                            break;
                        case WindowBorderEdge.Right:
                            cursorOffset.X = (Width - cursorLocation.X);
                            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;
//.........这里部分代码省略.........
开发者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: MouseLeftButtomDownMethod

        private void MouseLeftButtomDownMethod(FrameworkElement element, Point point)
        {
            isMouseCaptured = true;
            element.CaptureMouse();
            clickPoint = point;

            MakeFront(element);
        }
开发者ID:barbarossia,项目名称:CWF,代码行数:8,代码来源:DraggingWidgetHelper.cs

示例9: RegisterBorderEvents

        private void RegisterBorderEvents(DirectionOfResize DirectionOfResize, FrameworkElement border)
        {
            border.MouseLeftButtonDown += (sender, e) =>
            {
                Point cursorLocation = e.GetPosition(window);
                Point cursorOffset = new Point();

                switch (DirectionOfResize)
                {
                    case DirectionOfResize.Left:
                        cursorOffset.X = cursorLocation.X;
                        break;
                    case DirectionOfResize.TopLeft:
                        cursorOffset.X = cursorLocation.X;
                        cursorOffset.Y = cursorLocation.Y;
                        break;
                    case DirectionOfResize.Top:
                        cursorOffset.Y = cursorLocation.Y;
                        break;
                    case DirectionOfResize.TopRight:
                        cursorOffset.X = (window.Width - cursorLocation.X);
                        cursorOffset.Y = cursorLocation.Y;
                        break;
                    case DirectionOfResize.Right:
                        cursorOffset.X = (window.Width - cursorLocation.X);
                        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;
//.........这里部分代码省略.........
开发者ID:KiselevKN,项目名称:BootMega,代码行数:101,代码来源:WindowChrome.cs

示例10: 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

示例11: BackgroundAdorner_MouseLeftButtonDown

        public void BackgroundAdorner_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            MoveObj = null;
            MoveObj2 = null;
            MoveObj3 = null;

            MoveObj = sender as FrameworkElement;
            e.Handled = true;

            if (MoveObj is BottomKJ)
            {
                ButtomControl temp = MoveObj.Tag as ButtomControl;

                MoveObj2 = CBottom.FindName("x2" + temp.ID) as FrameworkElement;
                MoveObj3 = CBottom.FindName("x3" + temp.ID) as FrameworkElement;
            }

            MoveObj.CaptureMouse();
            MoveIsDown = true;
            BeginPoint = e.GetPosition(CBottom);
        }
开发者ID:ritacc,项目名称:QueueClient,代码行数:21,代码来源:ButtomAdmin.cs


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