Home
Manage Your Code
Snippet: Get Rounded Rectangle Path (C#)
Title: Get Rounded Rectangle Path Language: C#
Description: Get Rounded Rectangle Path for Rectangle Views: 225
Author: anton knier Date Added: 5/17/2008
Copy Code  
1     /// <summary>
2        /// Gets the path.
3        /// </summary>
4        /// <param name="rc">The rc.</param>
5        /// <param name="r">The radius for corner edges.</param>
6        /// <returns></returns>
7        private GraphicsPath GetPath(RectangleF rc, int r)
8        {
9    
10            float x = rc.X, y = rc.Y, w = rc.Width, h = rc.Height;
11            GraphicsPath path = new GraphicsPath();
12            path.AddArc(x, y, r, r, 180, 90);                //Upper left corner
13            path.AddArc(x + w - r, y, r, r, 270, 90);            //Upper right corner
14            path.AddArc(x + w - r, y + h - r, r, r, 0, 90);        //Lower right corner
15            path.AddArc(x, y + h - r, r, r, 90, 90);            //Lower left corner
16            path.CloseFigure();
17            return path;
18        }
Usage
            using(GraphicsPath path3 = GetPath(rc3, 10))
            {

                using (LinearGradientBrush br3 = new LinearGradientBrush(rc3, Color.White, Color.FromArgb(0, Color.White), LinearGradientMode.Vertical))
                {
                    _graphics.SetClip(path3);

                    _graphics.FillPath(br3, path3);	//draw shadow
                 
                }
            }