示例#1
0
        private void Canvas_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && !selectionBegin)
            {
                PointF pos = canvas.ScreenToWorld(new Point(e.X, e.Y));

                CanvasItem item = canvas.HitTest(pos);

                if (item != null)
                {
                    // Нажали внутри итема

                    if (!item.Selected)
                    {
                        // Если не выделен - выделить

                        if (canvas.GetModifierKeys() != Keys.Shift)
                        {
                            canvas.UnselectAll();
                        }

                        item.Select();
                        canvas.Invalidate();
                    }
                    else
                    {
                        // Если выделен - начать перетаскивание

                        selectedDragItems = canvas.GetSelected();

                        foreach (var next in selectedDragItems)
                        {
                            next.SavedPos    = new PointF(next.Pos.X, next.Pos.Y);
                            next.SavedPosEnd = new PointF(next.PosEnd.X, next.PosEnd.Y);

                            next.SavedPoints = new List <PointF>();
                            foreach (var point in next.Points)
                            {
                                next.SavedPoints.Add(point);
                            }
                        }

                        savedMouse    = new Point(e.X, e.Y);
                        draggingBegin = true;
                    }
                }
                else
                {
                    // Рамка выделения

                    List <PointF> points = new List <PointF>();

                    points.Add(pos);
                    points.Add(pos);
                    points.Add(pos);
                    points.Add(pos);
                    points.Add(pos);

                    selectionBox = new CanvasPolyLine(points);

                    selectionBox.FrontColor = Color.Black;

                    canvas.AddItem(selectionBox);

                    selectionBegin = true;
                }
            }

            else if (e.Button == MouseButtons.Right && !scrollingBegin)
            {
                savedScroll = new PointF(canvas.Scroll.X, canvas.Scroll.Y);
                savedMouse  = new Point(e.X, e.Y);

                canvas.Cursor = Cursors.SizeAll;

                scrollingBegin = true;
            }
        }