コード例 #1
0
        private WidgetInstance HitTest(Point mousePt, out DragMethod dragMethod)
        {
            if (_selectedWidget != null)
            {
                var dm = HitTest(_selectedWidget, mousePt);
                if (dm != DragMethod.None)
                {
                    dragMethod = dm;
                    return(_selectedWidget);
                }
            }

            foreach (var widget in (from w in _widgets where w != _selectedWidget select w))
            {
                var dm = HitTest(widget, mousePt);
                if (dm != DragMethod.None)
                {
                    dragMethod = dm;
                    return(widget);
                }
            }

            dragMethod = DragMethod.None;
            return(null);
        }
コード例 #2
0
        private void WidgetLayoutControl_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                if (_selectedWidget != null)
                {
                    if ((e.Button & System.Windows.Forms.MouseButtons.Left) != 0)
                    {
                        var screenPt = ScaledClientToScreen(e.Location);
                        var dist     = screenPt.Subtract(_lastScreenPt);

                        if (_dragMethod != DragMethod.None)
                        {
                            _dragging = true;
                        }

                        switch (_dragMethod)
                        {
                        case DragMethod.Move:
                            if (_selectedWidget.OffsetBoundsSafe(dist, false))
                            {
                                Invalidate();
                                OnWidgetsChanged(_selectedWidget);
                            }
                            break;

                        case DragMethod.ResizeTopLeft:
                        {
                            var bounds = _selectedWidget.Bounds;
                            if (_selectedWidget.ChangeBoundsSafe(new Rectangle(bounds.Left + dist.X, bounds.Top + dist.Y, bounds.Width - dist.X, bounds.Height - dist.Y), false))
                            {
                                Invalidate();
                                OnWidgetsChanged(_selectedWidget);
                            }
                        }
                        break;

                        case DragMethod.ResizeTopRight:
                        {
                            var bounds = _selectedWidget.Bounds;
                            if (_selectedWidget.ChangeBoundsSafe(new Rectangle(bounds.Left, bounds.Top + dist.Y, bounds.Width + dist.X, bounds.Height - dist.Y), false))
                            {
                                Invalidate();
                                OnWidgetsChanged(_selectedWidget);
                            }
                        }
                        break;

                        case DragMethod.ResizeBottomLeft:
                        {
                            var bounds = _selectedWidget.Bounds;
                            if (_selectedWidget.ChangeBoundsSafe(new Rectangle(bounds.Left + dist.X, bounds.Top, bounds.Width - dist.X, bounds.Height + dist.Y), false))
                            {
                                Invalidate();
                                OnWidgetsChanged(_selectedWidget);
                            }
                        }
                        break;

                        case DragMethod.ResizeBottomRight:
                        {
                            var bounds = _selectedWidget.Bounds;
                            if (_selectedWidget.ChangeBoundsSafe(new Rectangle(bounds.Left, bounds.Top, bounds.Width + dist.X, bounds.Height + dist.Y), false))
                            {
                                Invalidate();
                                OnWidgetsChanged(_selectedWidget);
                            }
                        }
                        break;
                        }

                        _lastScreenPt = screenPt;
                    }
                    else if (e.Button == System.Windows.Forms.MouseButtons.None)
                    {
                        _dragMethod = HitTest(_selectedWidget, e.Location);

                        switch (_dragMethod)
                        {
                        case DragMethod.Move:
                            this.Cursor = Cursors.SizeAll;
                            break;

                        case DragMethod.ResizeTopLeft:
                        case DragMethod.ResizeBottomRight:
                            this.Cursor = Cursors.SizeNWSE;
                            break;

                        case DragMethod.ResizeBottomLeft:
                        case DragMethod.ResizeTopRight:
                            this.Cursor = Cursors.SizeNESW;
                            break;

                        default:
                            this.Cursor = Cursors.Default;
                            break;
                        }
                    }
                    else
                    {
                        this.Cursor = Cursors.Default;
                    }
                }
            }
            catch (Exception ex)
            {
                this.ShowError(ex);
            }
        }
コード例 #3
0
ファイル: Shape.cs プロジェクト: helgihaf/Alpha
 private System.Windows.Forms.Cursor DragMethodToCursor(DragMethod method)
 {
     return cursorsByDragMethod[(int)method];
 }
コード例 #4
0
ファイル: Shape.cs プロジェクト: helgihaf/Alpha
 protected override void OnMouseUp(MouseEventArgs e)
 {
     base.OnMouseUp(e);
     dragStartLocation = null;
     dragMethod = DragMethod.None;
 }
コード例 #5
0
ファイル: Shape.cs プロジェクト: helgihaf/Alpha
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (e.Button == System.Windows.Forms.MouseButtons.None)
            {
                this.Cursor = DragMethodToCursor(GetDragMethod(e.Location));
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                if (dragStartLocation.HasValue)
                {
                    AdjustLocationOrShape(e.Location);
                    if (dragMethod == DragMethod.None)
                    {
                        dragMethod = GetDragMethod(e.Location);
                    }
                }
            }
        }
コード例 #6
0
 public static void SetDragMethod(DependencyObject target, DragMethod value)
 {
     target.SetValue(DragMethodProperty, value);
 }