/// <summary>
        /// Draw an arc on the canvas
        /// </summary>
        /// <param name="canvas">The canvas on which the arc is drawn</param>
        public void Draw(System.Drawing.Graphics canvas)
        {
            System.Drawing.Drawing2D.Matrix	matrix;
            double	startAngle, endAngle;

            matrix = canvas.Transform;

            canvas.TranslateTransform((m_points[0].x + m_points[1].x) / 2, (m_points[0].y + m_points[1].y) / 2);
            canvas.RotateTransform((float)(m_rotateAngle / System.Math.PI * 180));

            if (m_points[2].Equals(m_points[3]))
            {
                canvas.DrawEllipse(m_style.drawingStyle, -(m_points[1].x - m_points[0].x) / 2, -(m_points[1].y - m_points[0].y) / 2, m_points[1].x - m_points[0].x, m_points[1].y - m_points[0].y);
            }
            else
            {
                startAngle = System.Math.Atan2(m_points[2].y - (m_points[1].y + m_points[0].y) / 2, m_points[2].x - (m_points[1].x + m_points[0].x) / 2);
                if (startAngle < 0)
                {
                    startAngle += System.Math.PI * 2;
                }
                startAngle = (startAngle / Math.PI) * 180;

                endAngle = System.Math.Atan2(m_points[3].y - (m_points[1].y + m_points[0].y) / 2, m_points[3].x - (m_points[1].x + m_points[0].x) / 2);
                if (endAngle < 0)
                {
                    endAngle += System.Math.PI * 2;
                }
                endAngle = (endAngle / Math.PI) * 180;

                endAngle -= startAngle;
                if (endAngle < 0)
                {
                    endAngle += 360;
                }

                canvas.DrawArc(m_style.drawingStyle, -(m_points[1].x - m_points[0].x) / 2, -(m_points[1].y - m_points[0].y) / 2, m_points[1].x - m_points[0].x, m_points[1].y - m_points[0].y, (float)startAngle, (float)endAngle);
            }

            canvas.Transform = matrix;
        }
        public override void OnRender(System.Drawing.Graphics g)
        {
            if (IsVisible)
            {
                List<Point> points = new List<Point>();
                using (GraphicsPath rp = new GraphicsPath())
                {
                    for (int i = 0; i < LocalPoints.Count; i++)
                    {
                        GPoint p2 = LocalPoints[i];

                        points.Add(new Point(LocalPoints[i].X, LocalPoints[i].Y));
                        if (i == 0)
                        {
                            rp.AddLine(p2.X, p2.Y, p2.X, p2.Y);
                        }
                        else
                        {
                            System.Drawing.PointF p = rp.GetLastPoint();
                            rp.AddLine(p.X, p.Y, p2.X, p2.Y);
                        }
                        Pen pen = new Pen(Color.FromArgb(100, 255, 0, 0));
                        pen.Width = 1.5F;
                        if (_showNode)
                            g.DrawArc(pen, (float)LocalPoints[i].X - 3, (float)LocalPoints[i].Y - 3, 6, 6, (float)360, (float)360);
                    }

                    if (rp.PointCount > 0)
                    {
                        g.DrawPath(Stroke, rp);
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>This method will paint the control.</summary>
        /// <param name="g">The paint event graphics object.</param>
        private void PaintBack(System.Drawing.Graphics g)
        {
            //Set Graphics smoothing mode to Anit-Alias-- 
            g.SmoothingMode = SmoothingMode.AntiAlias;
            //-------------------------------------------

            //Declare Variables------------------
            int ArcWidth = this.RoundCorners * 2;
            int ArcHeight = this.RoundCorners * 2;
            int ArcX1 = 0;
            int ArcX2 = (this.ShadowControl) ? (this.Width - (ArcWidth + 1)) - this.ShadowThickness : this.Width - (ArcWidth + 1);
            int ArcY1 = 10;
            int ArcY2 = (this.ShadowControl) ? (this.Height - (ArcHeight + 1)) - this.ShadowThickness : this.Height - (ArcHeight + 1);

            int intXEnd = 20;

            if (GroupBoxAlignMode.Center == this._vGroupBoxAlignMode)
            {
                intXEnd += _vXTrans;
            }
            else if (GroupBoxAlignMode.Right == this._vGroupBoxAlignMode)
            {
                intXEnd += _vXTrans * 2;
            }
            int intTextLength = g.MeasureString(this.GroupTitle, this.Font).ToSize().Width + 34 - (ArcWidth + 1) - 20;
            int intXStart = intXEnd + intTextLength + ArcWidth;
            int X1 = intXEnd;
            int X2 = intXStart;

            if (this.GroupImage != null)
            {
                if (this.ShowTileRectangle)
                {
                    X2 += 18;
                }
                else
                {
                    X2 += 10;
                }
            }
            else
            {
                if (!this.ShowTileRectangle)
                {
                    X1 += 8 - this.TextLineSpace;
                    X2 -= 8 - this.TextLineSpace;
                }
            }
            X1 -= this.TitleLeftSpace;
            X2 -= this.TitleLeftSpace;

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            System.Drawing.Brush BorderBrush = new SolidBrush(this.BorderColor);
            System.Drawing.Pen BorderPen = new Pen(BorderBrush, this.BorderThickness);
            System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null;
            System.Drawing.Brush BackgroundBrush = new SolidBrush(this.BackgroundColor);
            System.Drawing.SolidBrush ShadowBrush = null;
            System.Drawing.Drawing2D.GraphicsPath ShadowPath = null;
            //-----------------------------------

            //Check if shadow is needed----------
            if (this.ShadowControl)
            {
                ShadowBrush = new SolidBrush(this.ShadowColor);
                ShadowPath = new System.Drawing.Drawing2D.GraphicsPath();
                ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left
                ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right
                ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right
                ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left
                ShadowPath.CloseAllFigures();

                //Paint Rounded Rectangle------------
                g.FillPath(ShadowBrush, ShadowPath);
                //-----------------------------------
            }
            //-----------------------------------
            //Edit BY WZW 2008-12-16
            //Create Rounded Rectangle Path------
            //path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left
            //path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right
            //path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right
            //path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left
            //path.CloseAllFigures(); 
            //g.DrawPath(BorderPen, path);
            //-----------------------------------
            //g.DrawArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle);

            //绘制标题外边框-----------------------


            //左上角
            g.DrawArc(BorderPen, ArcX1, ArcY1, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle);
            //左上至右上分两段画线,两段之间为标题外框
            BorderPen = new Pen(BorderBrush, this.BorderThickness);
            g.DrawLine(BorderPen, new Point(ArcX1 + this.RoundCorners, ArcY1), new Point(X1, ArcY1));//左边一段直线
            BorderPen = new Pen(BorderBrush, this.BorderThickness);
            g.DrawLine(BorderPen, new Point(X2, ArcY1), new Point(ArcX2 + this.RoundCorners, ArcY1));//右边一段直线

            //右上角
            g.DrawArc(BorderPen, ArcX2, ArcY1, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle);

            if (!_vBorderTopOnly)
            {
                //右上至右下
                g.DrawLine(BorderPen, new Point(ArcX2 + ArcWidth, ArcY1 + this.RoundCorners), new Point(ArcX2 + ArcHeight, ArcY2 + this.RoundCorners));
                //右下角

                g.DrawArc(BorderPen, ArcX2, ArcY2, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle);
                //右下至左下

                g.DrawLine(BorderPen, new Point(ArcX2 + this.RoundCorners, ArcY2 + ArcWidth), new Point(ArcX1 + this.RoundCorners, ArcY2 + ArcWidth));
                //左下角
                g.DrawArc(BorderPen, ArcX1, ArcY2, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle);
                //左下只左上
                g.DrawLine(BorderPen, new Point(ArcX1, ArcY2 + this.RoundCorners), new Point(ArcX1, ArcY1 + this.RoundCorners));
                //g.DrawPath(BorderPen, path);
            }

            //Check if Gradient Mode is enabled--
            if (this.BackgroundGradientMode == GroupBoxGradientMode.None)
            {
                //Paint Rounded Rectangle------------
                g.FillPath(BackgroundBrush, path);
                //-----------------------------------
            }
            else
            {
                BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.BackgroundColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode);

                //Paint Rounded Rectangle------------
                g.FillPath(BackgroundGradientBrush, path);
                //-----------------------------------
            }
            //-----------------------------------

            //Delete BY WZW 
            //Paint Borded-----------------------
            //g.DrawPath(BorderPen, path);
            //g.DrawLine(SystemPens.Control, 10, 10, 100, 10);
            //-----------------------------------

            //Destroy Graphic Objects------------
            if (path != null) { path.Dispose(); }
            if (BorderBrush != null) { BorderBrush.Dispose(); }
            if (BorderPen != null) { BorderPen.Dispose(); }
            if (BackgroundGradientBrush != null) { BackgroundGradientBrush.Dispose(); }
            if (BackgroundBrush != null) { BackgroundBrush.Dispose(); }
            if (ShadowBrush != null) { ShadowBrush.Dispose(); }
            if (ShadowPath != null) { ShadowPath.Dispose(); }
            //-----------------------------------
        }