示例#1
0
        private PaintGraphicsPath GetCapsule(PaintRectangleF baseRect)
        {
            float             diameter;
            PaintRectangleF   arc;
            PaintGraphicsPath path = new PaintGraphicsPath(new GraphicsPath());

            try
            {
                if (baseRect.Width > baseRect.Height)
                {
                    diameter = baseRect.Height;
                    ShaipSizeF sizeF = new ShaipSizeF(diameter, diameter);
                    arc = new PaintRectangleF(baseRect.Location, sizeF);
                    path.AddArc(arc, 90, 180);
                    arc.X = baseRect.Right - diameter;
                    path.AddArc(arc, 270, 180);
                }
                else if (baseRect.Width < baseRect.Height)
                {
                    diameter = baseRect.Width;
                    ShaipSizeF sizeF = new ShaipSizeF(diameter, diameter);
                    arc = new PaintRectangleF(baseRect.Location, sizeF);
                    path.AddArc(arc, 180, 180);
                    arc.Y = baseRect.Bottom - diameter;
                    path.AddArc(arc, 0, 180);
                }
                else
                {
                    path.AddEllipse(baseRect);
                }
            }
            catch (Exception)
            {
                path.AddEllipse(baseRect);
            }
            finally
            {
                path.CloseFigure();
            }
            return(path);
        }
示例#2
0
        private PaintGraphicsPath GetRoundRectangle(PaintRectangleF baseRect, float radius)
        {
            if (radius <= 0.0F)
            {
                PaintGraphicsPath mPath = new PaintGraphicsPath(new GraphicsPath());
                mPath.AddRectangle(baseRect);
                mPath.CloseFigure();
                return(mPath);
            }


            if (radius >= (Math.Min(baseRect.Width, baseRect.Height)) / 2.0)
            {
                return(GetCapsule(baseRect));
            }


            float             diameter = radius * 2.0F;
            ShaipSizeF        sizeF    = new ShaipSizeF(diameter, diameter);
            PaintRectangleF   arc      = new PaintRectangleF(baseRect.Location, sizeF);
            PaintGraphicsPath path     = new PaintGraphicsPath(new GraphicsPath());


            path.AddArc(arc, 180, 90);


            arc.X = baseRect.Right - diameter;
            path.AddArc(arc, 270, 90);


            arc.Y = baseRect.Bottom - diameter;
            path.AddArc(arc, 0, 90);


            arc.X = baseRect.Left;
            path.AddArc(arc, 90, 90);

            path.CloseFigure();
            return(path);
        }