MFC怎么绘制一个圆角矩形
答案:3 悬赏:50 手机版
解决时间 2021-03-22 19:43
- 提问者网友:不要迷恋哥
- 2021-03-22 07:58
MFC怎么绘制一个圆角矩形
最佳答案
- 五星知识达人网友:鸽屿
- 2021-03-22 08:49
参考代码如下:
#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;
}
#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;
}
全部回答
- 1楼网友:春色三分
- 2021-03-22 10:58
CRect rect = lpDrawItemStruct->rcItem;
CDC *pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
POINT pt ;
//画按钮的外边框,它是一个半径为5的圆角矩形
pt.x =5;
pt.y =5;
CPen* hOldPen = pDC->SelectObject(&m_BoundryPen);
pDC->RoundRect(&rect, pt);
pDC->SelectObject(hOldPen);
rect.DeflateRect(CSize(GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE)));
CBrush brush(m_color);
pDC->FillRect(rect,&brush );
brush.DeleteObject();
CDC *pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
POINT pt ;
//画按钮的外边框,它是一个半径为5的圆角矩形
pt.x =5;
pt.y =5;
CPen* hOldPen = pDC->SelectObject(&m_BoundryPen);
pDC->RoundRect(&rect, pt);
pDC->SelectObject(hOldPen);
rect.DeflateRect(CSize(GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE)));
CBrush brush(m_color);
pDC->FillRect(rect,&brush );
brush.DeleteObject();
- 2楼网友:北方的南先生
- 2021-03-22 09:23
CRect rect = lpDrawItemStruct->rcItem;
CDC *pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
POINT pt ;
//画按钮的外边框,它是一个半径为5的圆角矩形
pt.x =5;
pt.y =5;
CPen* hOldPen = pDC->SelectObject(&m_BoundryPen);
pDC->RoundRect(&rect, pt);
pDC->SelectObject(hOldPen);
rect.DeflateRect(CSize(GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE)));
CBrush brush(m_color);
pDC->FillRect(rect,&brush );
brush.DeleteObject();
CDC *pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
POINT pt ;
//画按钮的外边框,它是一个半径为5的圆角矩形
pt.x =5;
pt.y =5;
CPen* hOldPen = pDC->SelectObject(&m_BoundryPen);
pDC->RoundRect(&rect, pt);
pDC->SelectObject(hOldPen);
rect.DeflateRect(CSize(GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE)));
CBrush brush(m_color);
pDC->FillRect(rect,&brush );
brush.DeleteObject();
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯