// Пример взят с сайта http://blog.opennetcf.org/ayakhnin/default.aspx
// Автор примера - Alex Yakhnin

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DrawRoundedRectangle_CS
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            #if DEBUG
                MinimizeBox = false;
            #else
                MinimizeBox = true;
            #endif
        }

        public static void DrawRoundedRectangle(Graphics g, Pen p, Color backColor, Rectangle rc, Size size)
        {
            Point[] points = new Point[8];

            // подготовим точки для фигуры
            points[0].X = rc.Left + size.Width / 2;
            points[0].Y = rc.Top + 1;
            points[1].X = rc.Right - size.Width / 2;
            points[1].Y = rc.Top + 1;
            points[2].X = rc.Right;
            points[2].Y = rc.Top + size.Height / 2;
            points[3].X = rc.Right;
            points[3].Y = rc.Bottom - size.Height / 2;
            points[4].X = rc.Right - size.Width / 2;
            points[4].Y = rc.Bottom;
            points[5].X = rc.Left + size.Width / 2;
            points[5].Y = rc.Bottom;
            points[6].X = rc.Left + 1;
            points[6].Y = rc.Bottom - size.Height / 2;
            points[7].X = rc.Left + 1;
            points[7].Y = rc.Top + size.Height / 2;

            // приготовим кисть для фона
            using (Brush fillBrush = new SolidBrush(backColor))
            {
                // рисуем отрезки и кружки для округленного прямоугольника
                g.DrawLine(p, rc.Left + size.Width / 2, rc.Top,
                 rc.Right - size.Width / 2, rc.Top);
                g.FillEllipse(fillBrush, rc.Right - size.Width, rc.Top,
                 size.Width, size.Height);
                g.DrawEllipse(p, rc.Right - size.Width, rc.Top,
                 size.Width, size.Height);
                g.DrawLine(p, rc.Right, rc.Top + size.Height / 2,
                 rc.Right, rc.Bottom - size.Height / 2);
                g.FillEllipse(fillBrush, rc.Right - size.Width, rc.Bottom - size.Height,
                 size.Width, size.Height);
                g.DrawEllipse(p, rc.Right - size.Width, rc.Bottom - size.Height,
                 size.Width, size.Height);

                g.DrawLine(p, rc.Right - size.Width / 2, rc.Bottom,
                 rc.Left + size.Width / 2, rc.Bottom);
                g.FillEllipse(fillBrush, rc.Left, rc.Bottom - size.Height,
                 size.Width, size.Height);
                g.DrawEllipse(p, rc.Left, rc.Bottom - size.Height,
                 size.Width, size.Height);

                g.DrawLine(p, rc.Left, rc.Bottom - size.Height / 2,
                 rc.Left, rc.Top + size.Height / 2);
                g.FillEllipse(fillBrush, rc.Left, rc.Top,
                 size.Width, size.Height);
                g.DrawEllipse(p, rc.Left, rc.Top,
                 size.Width, size.Height);


                // заполняем прямоугольник, скрывая внутренние эллипсы  
                g.FillPolygon(fillBrush, points);
            }
        }

        private void butDrawRoundedRectangle_Click(object sender, EventArgs e)
        {
            using (Graphics g = CreateGraphics())
            {
                Rectangle rc = new Rectangle(10, 10, 200, 50);

                DrawRoundedRectangle(g,
                    new Pen(Color.Black), Color.CadetBlue, rc, new Size(8, 8));
            }
        }

    }
}