GDI+/GDI Plusを描き、丸い長方形のDraw retangle roundを描きます。

1915 ワード

参考は以下の通りです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;
}