示例#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();
            }
        }
示例#2
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;
            }
        }
示例#3
0
        private void DrawOperate(Graphics g)
        {
            foreach (OperateObject obj in OperateManager.OperateList)
            {
                switch (obj.OperateType)
                {
                case OperateType.DrawRectangle:
                    using (Pen pen = new Pen(obj.Color))
                    {
                        g.DrawRectangle(
                            pen,
                            (Rectangle)obj.Data);
                    }
                    break;

                case OperateType.DrawEllipse:
                    using (Pen pen = new Pen(obj.Color))
                    {
                        g.DrawEllipse(
                            pen,
                            (Rectangle)obj.Data);
                    }
                    break;

                case OperateType.DrawArrow:
                    Point[] points = obj.Data as Point[];
                    using (Pen pen = new Pen(obj.Color))
                    {
                        pen.EndCap       = LineCap.Custom;
                        pen.CustomEndCap = new AdjustableArrowCap(4, 4, true);
                        g.DrawLine(pen, points[0], points[1]);
                    }
                    break;

                case OperateType.DrawText:
                    DrawTextData textdata = obj.Data as DrawTextData;

                    if (string.IsNullOrEmpty(textdata.Text))
                    {
                        using (Pen pen = new Pen(obj.Color))
                        {
                            pen.DashStyle   = DashStyle.DashDot;
                            pen.DashCap     = DashCap.Round;
                            pen.DashPattern = new float[] { 9f, 3f, 3f, 3f };
                            g.DrawRectangle(
                                pen,
                                textdata.TextRect);
                        }
                    }
                    else
                    {
                        using (SolidBrush brush = new SolidBrush(obj.Color))
                        {
                            g.DrawString(
                                textdata.Text,
                                textdata.Font,
                                brush,
                                textdata.TextRect);
                        }
                    }
                    break;

                case OperateType.DrawLine:
                    using (Pen pen = new Pen(obj.Color))
                    {
                        g.DrawLines(pen, obj.Data as Point[]);
                    }
                    break;
                }
            }
        }
示例#4
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;
            }
        }