예제 #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 (this.pictureBox1.OperateManager.OperateCount > 0)
                {
                    OperateObject obj =
                        this.pictureBox1.OperateManager.OperateList[this.pictureBox1.OperateManager.OperateCount - 1];
                    if (obj.OperateType == OperateType.DrawText)
                    {
                        DrawTextData textData = obj.Data as DrawTextData;
                        if (!textData.Completed)
                        {
                            if (string.IsNullOrEmpty(text))
                            {
                                this.pictureBox1.OperateManager.RedoOperate();
                            }
                            else
                            {
                                obj.Color          = color;
                                textData.Font      = font;
                                textData.Text      = text;
                                textData.Completed = true;
                            }
                        }
                    }
                }
                base.Invalidate();
            }
        }
예제 #2
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.DrawLine:
                    using (Pen pen = new Pen(obj.Color))
                    {
                        g.DrawLines(pen, obj.Data as Point[]);
                    }
                    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;
                }
            }
        }
예제 #3
0
        private void AddOperate(Point point)
        {
            Color color = this.SelectColor;

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

            case DrawStyle.Ellipse:
                OperateManager.AddOperate(
                    OperateType.DrawEllipse,
                    color,
                    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.Line:
                if (LinePointList.Count < 2)
                {
                    return;
                }
                OperateManager.AddOperate(
                    OperateType.DrawLine,
                    color,
                    LinePointList.ToArray());
                LinePointList.Clear();
                break;

            case DrawStyle.Text:
                EventHandler handler = base.Events[EventTextBoxShow] as EventHandler;
                if (handler != null)
                {
                    handler(this, new EventArgs());
                }
                Rectangle textRect = 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;
            }
        }