Ejemplo n.º 1
0
        private void TextBoxExLostFocus(object sender, EventArgs e)
        {
            if (textBox.Visible)
            {
                string text  = textBox.Text;
                Font   font  = textBox.Font;
                Color  color = textBox.ForeColor;

                HideTextBox();
                if (OperateManager.OperateCount > 0)
                {
                    OperateObject obj =
                        OperateManager.OperateList[OperateManager.OperateCount - 1];
                    if (obj.OperateType == OperateType.DrawText)
                    {
                        DrawTextData textData = obj.Data as DrawTextData;
                        if (!textData.Completed)
                        {
                            if (string.IsNullOrEmpty(text))
                            {
                                OperateManager.RedoOperate();
                            }
                            else
                            {
                                obj.Color          = color;
                                textData.Font      = font;
                                textData.Text      = text;
                                textData.Completed = true;
                            }
                        }
                    }
                }
                base.Invalidate();
            }
        }
Ejemplo n.º 2
0
        private void ResetSelectImage()
        {
            SelectedImage      = false;
            _selectImageBounds = Rectangle.Empty;
            SelectImageRect    = Rectangle.Empty;
            SizeGrip           = SizeGrip.None;

            HideDrawToolsControl();
            if (textBox.Visible)
            {
                HideTextBox();
            }
            OperateManager.Clear();
            base.Invalidate();
        }
Ejemplo n.º 3
0
 private void DrawToolsControlButtonRedoClick(object sender, EventArgs e)
 {
     if (OperateManager.OperateCount > 0)
     {
         OperateManager.RedoOperate();
         base.Invalidate();
     }
     else
     {
         if (SelectedImage)
         {
             ResetSelectImage();
             base.Invalidate();
         }
     }
 }
Ejemplo n.º 4
0
        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);
            if (_sizeGripRectList != null)
            {
                _sizeGripRectList.Clear();
                _sizeGripRectList = null;
            }
            if (_operateManager != null)
            {
                _operateManager.Dispose();
                _operateManager = null;
            }
            if (_linePointList != null)
            {
                _linePointList.Clear();
                _linePointList = null;
            }

            _selectCursor = null;
            _drawCursor   = null;
        }
Ejemplo n.º 5
0
        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);
            if (_sizeGripRectList != null)
            {
                _sizeGripRectList.Clear();
                _sizeGripRectList = null;
            }
            if (_operateManager != null)
            {
                _operateManager.Dispose();
                _operateManager = null;
            }
            if (_linePointList != null)
            {
                _linePointList.Clear();
                _linePointList = null;
            }

            _selectCursor = null;
            _drawCursor = null;
        }
Ejemplo n.º 6
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (textBox.Visible)
            {
                if (SelectImageRect.Contains(e.Location) ||
                    e.Button == MouseButtons.Left)
                {
                    string text  = textBox.Text;
                    Font   font  = textBox.Font;
                    Color  color = textBox.ForeColor;

                    HideTextBox();
                    if (OperateManager.OperateCount > 0)
                    {
                        OperateObject obj =
                            OperateManager.OperateList[OperateManager.OperateCount - 1];
                        if (obj.OperateType == OperateType.DrawText)
                        {
                            DrawTextData textData = obj.Data as DrawTextData;
                            if (!textData.Completed)
                            {
                                if (string.IsNullOrEmpty(text))
                                {
                                    OperateManager.RedoOperate();
                                }
                                else
                                {
                                    obj.Color          = color;
                                    textData.Font      = font;
                                    textData.Text      = text;
                                    textData.Completed = true;
                                }
                            }
                        }
                    }
                }
                base.Invalidate();
                return;
            }

            if (e.Button == MouseButtons.Left)
            {
                if (SelectedImage)
                {
                    if (SizeGrip != SizeGrip.None)
                    {
                        _mouseDown      = true;
                        _mouseDownPoint = e.Location;
                        HideDrawToolsControl();
                        base.Invalidate();
                    }

                    if (DrawStyle != DrawStyle.None)
                    {
                        if (SelectImageRect.Contains(e.Location))
                        {
                            _mouseDown      = true;
                            _mouseDownPoint = e.Location;

                            if (DrawStyle == DrawStyle.Line)
                            {
                                LinePointList.Add(_mouseDownPoint);
                            }
                            ClipCursor(false);
                        }
                    }
                }
                else
                {
                    _mouseDown      = true;
                    _mouseDownPoint = e.Location;
                }
            }

            if (e.Button == MouseButtons.Right)
            {
                this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                return;
            }
        }
Ejemplo n.º 7
0
        private void AddOperate(Point point)
        {
            if (!SelectImageRect.Contains(_mouseDownPoint))
            {
                return;
            }

            Color color = SelectedColor;

            switch (DrawStyle)
            {
            case DrawStyle.Rectangle:
                OperateManager.AddOperate(
                    OperateType.DrawRectangle,
                    color,
                    ImageBoundsToRect(Rectangle.FromLTRB(
                                          _mouseDownPoint.X,
                                          _mouseDownPoint.Y,
                                          point.X,
                                          point.Y)));
                break;

            case DrawStyle.Ellipse:
                OperateManager.AddOperate(
                    OperateType.DrawEllipse,
                    color,
                    ImageBoundsToRect(Rectangle.FromLTRB(
                                          _mouseDownPoint.X,
                                          _mouseDownPoint.Y,
                                          point.X,
                                          point.Y)));
                break;

            case DrawStyle.Arrow:
                Point[] points = new Point[] { _mouseDownPoint, point };
                OperateManager.AddOperate(
                    OperateType.DrawArrow,
                    color,
                    points);
                break;

            case DrawStyle.Text:
                ShowTextBox();
                Rectangle textRect = ImageBoundsToRect(Rectangle.FromLTRB(
                                                           _mouseDownPoint.X,
                                                           _mouseDownPoint.Y,
                                                           point.X,
                                                           point.Y));
                DrawTextData textData = new DrawTextData(
                    string.Empty,
                    base.Font,
                    textRect);

                OperateManager.AddOperate(
                    OperateType.DrawText,
                    color,
                    textData);
                break;

            case DrawStyle.Line:
                if (LinePointList.Count < 2)
                {
                    return;
                }
                OperateManager.AddOperate(
                    OperateType.DrawLine,
                    color,
                    LinePointList.ToArray());
                LinePointList.Clear();
                break;
            }
        }