参考如下:http://sbje5201314.blog.163.com/blog/static/28033862007026104233469/
这是修改过的适合VC++的,目的是画一个圆角矩形,然后用同样颜色填充,没有阴影哦:
#define OFFSET_X 5
#define OFFSET_Y 5
void DrawRoundRectange(Graphics &g,Color pens,int x,int y,int width,int height)
{
//设置画图时的滤波模式为消除锯齿现象
g.SetSmoothingMode(SmoothingModeAntiAlias);
//创建一个红色的画笔
Pen *pen = new Pen(pens,1);
//画矩形上面的边
g.DrawLine(pen,x+OFFSET_X,y,width-OFFSET_X,y);
//画矩形下面的边
g.DrawLine(pen,x+OFFSET_X,y+height,width-OFFSET_X,y+height);
//画矩形左面的边
g.DrawLine(pen,x,y+OFFSET_Y,x,y+height-OFFSET_Y);
//画矩形右面的边
g.DrawLine(pen,x+width,y+OFFSET_Y,x+width,y+height-OFFSET_Y);
//画矩形左上角的圆角
g.DrawArc(pen,x,y,OFFSET_X*2,OFFSET_Y*2,180,90);
//画矩形右下角的圆角
g.DrawArc(pen,x+width-OFFSET_X*2,y+height-OFFSET_Y*2,OFFSET_X*2,OFFSET_Y*2,360,90);
//画矩形右上角的圆角
g.DrawArc(pen,x+width-OFFSET_X*2,y,OFFSET_X*2,OFFSET_Y*2,270,90);
//画矩形左下角的圆角
g.DrawArc(pen,x,y+height-OFFSET_Y*2,OFFSET_X*2,OFFSET_Y*2,90,90);
delete pen;
}
/* 填充颜色 */
void FillRoundRectangle(Graphics &g,Color color,int x,int y,int width,int height)
{
//矩形填充的步骤:
//1、把圆角矩形画分为四个圆角上分成四个同等的扇形外加三个直角矩形
//2、先填充三个直角矩形
//3、然后填充四个角上的扇形
//创建画刷
Brush *brush = new SolidBrush(color);
//填充三个直角矩形
g.FillRectangle(brush,x,y+OFFSET_Y,width,height-OFFSET_Y*2);
g.FillRectangle(brush,x+OFFSET_X,y,width-OFFSET_X*2,height);
//填充四个角上的扇形区
//填充左上角扇形
#define PIE_OFFSET 2
g.FillPie(brush,x,y,OFFSET_X*2+PIE_OFFSET,OFFSET_Y*2+PIE_OFFSET,180,90);
//填充右下角的扇形
g.FillPie(brush,x+width-(OFFSET_X*2+PIE_OFFSET),y+height-(OFFSET_Y*2+PIE_OFFSET),OFFSET_X*2+PIE_OFFSET,OFFSET_Y*2+PIE_OFFSET,360,90);
//填充右上角的扇形
g.FillPie(brush,x+width-(OFFSET_X*2+PIE_OFFSET),y,(OFFSET_X*2+PIE_OFFSET),(OFFSET_Y*2+PIE_OFFSET),270,90);
//填充左下角的扇形
g.FillPie(brush,x,y+height-(OFFSET_X*2+PIE_OFFSET),(OFFSET_X*2+PIE_OFFSET),(OFFSET_Y*2+PIE_OFFSET),90,90);
delete brush;
}