Archive for Maggio 18th, 2008

Get Rounded Rectangle Path

CodeKeep C# Feed Maggio 18th, 2008

Description: Get Rounded Rectangle Path for Rectangle

Link: http://www.codekeep.net/snippets/f292c56e-be89-4562-aac9-6722649659e4.aspx

     /// <summary>
        /// Gets the path.
        /// </summary>
        /// <param name="rc">The rc.</param>
        /// <param name="r">The radius for corner edges.</param>
        /// <returns></returns>
        private GraphicsPath GetPath(RectangleF rc, int r)
        {

            float x = rc.X, y = rc.Y, w = rc.Width, h = rc.Height;
            GraphicsPath path = new GraphicsPath();
            path.AddArc(x, y, r, r, 180, 90);				//Upper left corner
            path.AddArc(x + w - r, y, r, r, 270, 90);			//Upper right corner
            path.AddArc(x + w - r, y + h - r, r, r, 0, 90);		//Lower right corner
            path.AddArc(x, y + h - r, r, r, 90, 90);			//Lower left corner
            path.CloseFigure();
            return path;
        }