Exemplo n.º 1
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            // Khi di chuyển chuột (và đè chuột trái - tức đang vẽ) trên vùng DrawBox
            // Với các trường hợp vẽ hình: liên tục cập nhật lại DrawBox để tạo độ mượt
            // (xét trường hợp có đè nút Shift tạo hình vuông) ở phần vẽ hình

            base.OnMouseMove(e);

            switch (_drawStatus)
            {
            case DrawStatus.LineDrawing:
                ptMouseMove = e.Location;
                break;

            case DrawStatus.ToolDrawing:
                DrawDrag(ptMouseDown, e.Location, MyPaint.DrawType);
                ptMouseDown = e.Location;
                break;

            case DrawStatus.TextDrawing:
                areaRect = ShapePaint.CreateRectangle(ptMouseDown, e.Location);
                break;

            case DrawStatus.ShapeDrawing:
                if (ModifierKeys == Keys.Shift)
                {
                    areaRect = ShapePaint.CreateSquare(ptMouseDown, e.Location);
                }
                else
                {
                    areaRect = ShapePaint.CreateRectangle(ptMouseDown, e.Location);
                }
                break;

            case DrawStatus.EditDrawing:
                _dragHandle = EditPaint.GetDragHandle(e.Location, areaRect);
                if (_dragHandle < 9)
                {
                    UpdateCursor();
                }
                else if (areaRect.Contains(e.Location))
                {
                    Cursor = Cursors.SizeAll;
                }
                else
                {
                    Cursor = Cursors.Default;
                }
                break;

            case DrawStatus.ResizingShape:
                EditPaint.UpdateResizeRect(ref areaRect, oldRect, ptMouseDown, e.Location, _dragHandle);
                break;

            case DrawStatus.MovingShape:
                EditPaint.UpdateMoveRect(ref areaRect, oldRect, ptMouseDown, e.Location);
                break;
            }
            this.Invalidate();
        }
Exemplo n.º 2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            // Vẽ liên tục các hình tạm trên DrawBox nhằm tạo độ mượt

            base.OnPaint(e);

            switch (_drawStatus)
            {
            case DrawStatus.LineDrawing:
                e.Graphics.DrawLine(_pen, ptMouseDown, ptMouseMove);
                break;

            case DrawStatus.TextDrawing:
                ShapePaint.DrawShape(e.Graphics, _pen, areaRect, "Rectangle");
                break;

            case DrawStatus.ShapeDrawing:
                ShapePaint.DrawShape(e.Graphics, _pen, areaRect, MyPaint.DrawType);
                break;

            case DrawStatus.ResizingShape:
            case DrawStatus.MovingShape:
            case DrawStatus.EditDrawing:
                if (MyPaint.DrawType == "Text")
                {
                    if (areaRect.Height < textRect.Height)
                    {
                        areaRect.Height = textRect.Height;
                        ShapePaint.DrawShape(e.Graphics, _pen, areaRect, "Rectangle");
                    }
                }
                else
                {
                    ShapePaint.DrawShape(e.Graphics, _pen, areaRect, MyPaint.DrawType);
                }
                EditPaint.DrawDragRectangle(e.Graphics, areaRect);
                break;
            }
        }
Exemplo n.º 3
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            // Nhấc chuột lên: Hoàn thành vẽ với vẽ đường thẳng, các trường hợp còn lại chuyển sang Resize

            base.OnMouseUp(e);

            switch (_drawStatus)
            {
            case DrawStatus.LineDrawing:
                _g = Graphics.FromImage(Image);
                if (ptMouseDown != ptMouseMove)
                {
                    UndoList.Push(new Bitmap(Image));
                    RedoList.Clear();
                    _g.DrawLine(_pen, ptMouseDown, ptMouseMove);
                    RedoList.Push(new Bitmap(Image));
                }
                _drawStatus = DrawStatus.Idle;
                break;

            case DrawStatus.ToolDrawing:
                _drawStatus = DrawStatus.Idle;
                RedoList.Push(new Bitmap(Image));
                break;

            case DrawStatus.TextDrawing:
                if (areaRect != Rectangle.Empty)
                {
                    _drawStatus = DrawStatus.EditDrawing;
                    DrawTextBox(null);
                }
                else
                {
                    _drawStatus = DrawStatus.Idle;
                }
                break;

            case DrawStatus.ShapeDrawing:
                _g = CreateGraphics();
                if (areaRect.Width > 1 && areaRect.Height > 1 && ptMouseDown != e.Location)
                {
                    UndoList.Push(new Bitmap(Image));
                    RedoList.Clear();
                    ShapePaint.DrawShape(_g, _pen, areaRect, MyPaint.DrawType);
                    EditPaint.DrawDragRectangle(_g, areaRect);
                    _drawStatus = DrawStatus.EditDrawing;
                }
                else
                {
                    _drawStatus = DrawStatus.Idle;
                }
                break;

            case DrawStatus.ResizingShape:
            case DrawStatus.MovingShape:
                if (MyPaint.DrawType == "Text")
                {
                    textBoxPopUp.Dispose();
                    DrawTextBox(TextToDraw);
                }
                _drawStatus = DrawStatus.EditDrawing;
                break;
            }
        }