Ejemplo n.º 1
0
        void DrawString_WhenPressEscape(object sender, KeyEventArgs e)
        {
            PopupTextBox s = sender as PopupTextBox;

            if (e.KeyCode == Keys.Escape)
            {
                s.Dispose();
                _drawStatus = DrawStatus.Idle;
            }
        }
Ejemplo n.º 2
0
        // Khởi tạo các thuộc tính khi nhấn chuột trái vào vùng DrawBox
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            ptMouseDown = ptMouseMove = e.Location;

            switch (_drawStatus)
            {
            // Trường hơp chưa vẽ: lấy màu vẽ
            case DrawStatus.Idle:
                if (e.Button == MouseButtons.Left)
                {
                    _drawColor = MyPaint.LeftColor;
                }

                else if (e.Button == MouseButtons.Right)
                {
                    _drawColor = MyPaint.RightColor;
                }

                SetGraphics();
                break;

            // Đang chỉnh hình (Edit, Resize): căn cứ con trỏ chuột đang trỏ chuột:
            // Trỏ chuột trên 8 ô Resize: chuyển sang trạng thái Resize hình
            // Trỏ chuột trong hình: Chuyển sang trạng thái Move hình
            // Trỏ chuột ngoài hình: Kết thúc và vẽ hình

            case DrawStatus.EditDrawing:
                if (_dragHandle != 9)
                {
                    oldRect     = areaRect;
                    _drawStatus = DrawStatus.ResizingShape;
                }

                else if (areaRect.Contains(e.Location))
                {
                    oldRect     = areaRect;
                    _drawStatus = DrawStatus.MovingShape;
                }

                else
                {
                    _drawStatus = DrawStatus.Idle;
                    _g          = Graphics.FromImage(Image);

                    if (MyPaint.DrawType == "Text")
                    {
                        if (TextToDraw != null)
                        {
                            UndoList.Push(new Bitmap(Image));
                            RedoList.Clear();
                            AddText(TextToDraw, areaRect);
                            RedoList.Push(new Bitmap(Image));
                        }
                        textBoxPopUp.Dispose();
                    }
                    else
                    {
                        ShapePaint.DrawShape(_g, _pen, areaRect, MyPaint.DrawType);
                        RedoList.Push(new Bitmap(Image));
                    }
                    areaRect = Rectangle.Empty;
                    this.Invalidate();
                }
                break;
            }
        }