VC++ 绘制圆角矩形

自绘CButton,想在获取焦点的时候给按钮添加一个虚线外框,觉得圆角矩形好看点,于是写了一个。

Gdiplus::Pen pen(Color(255, rColor, gColor, bColor));
pen.SetDashStyle(Gdiplus::DashStyle::DashStyleDot);
// 直角矩形
//g.DrawRectangle(&pen, rcClient.left+1, rcClient.top+1, rcClient.Width()-2, rcClient.Height()-2);
// 圆角矩形
int nRadius = 2;// 圆角半径
GraphicsPath* path = new GraphicsPath;
path->StartFigure();
path->AddArc((REAL)rcClient.left, (REAL)rcClient.top, (REAL)nRadius * 2, (REAL)nRadius * 2, 180.0, 90.0);
path->AddArc((REAL)rcClient.left + rcClient.Width() - nRadius * 2, (REAL)rcClient.top, (REAL)nRadius * 2, (REAL)nRadius * 2, 270.0, 90.0);
path->AddArc((REAL)rcClient.left + rcClient.Width() - nRadius * 2, (REAL)rcClient.top + rcClient.Height() - nRadius * 2, (REAL)nRadius * 2, (REAL)nRadius * 2, 0.0, 90.0);
path->AddArc((REAL)rcClient.left, (REAL)rcClient.top + rcClient.Height() - nRadius * 2, (REAL)nRadius * 2, (REAL)nRadius * 2, 90.0, 90.0);
path->CloseFigure();
g.DrawPath(&pen, path);//这里绘制的是矩形边框,如果是绘制实心的,DrawPath换成FillPath即可
delete path;
path = NULL;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值