Status FillRectangle(IN const Brush* brush,
IN const RectF& rect)
{
return FillRectangle(brush, rect.X, rect.Y, rect.Width, rect.Height);
}
现象:
CPaintDC dcParent(GetParent());
Gdiplus::Color colorBk;
colorBk.SetFromCOLORREF(dcParent.GetBkColor());
Gdiplus::SolidBrush brushClient(colorBk);
g->FillRectangle(&brushClient, Gdiplus::RectF(rect.left, rect.top, rect.Width(), rect.Height()));
直接把窗体的客户区域赋值给第二个参数rect,会多出两条线,大致如下:
原因:
gdi+绘制的时候并不是按我们指定的坐标开始填充的,它分别向上和向左平移一个像素。
解决方案:
调整输入参数,x和y方向各自减去1.0,宽度和高度各自加1.0,修改后代码和效果如下:
CPaintDC dcParent(GetParent());
Gdiplus::Color colorBk;
colorBk.SetFromCOLORREF(dcParent.GetBkColor());
Gdiplus::SolidBrush brushClient(colorBk);
//g->FillRectangle(&brushClient, Gdiplus::RectF(rect.left, rect.top, rect.Width(), rect.Height()));
g->FillRectangle(&brushClient, Gdiplus::RectF(rect.left - 1.0, rect.top - 1.0, rect.Width() + 1.0, rect.Height()+ 1.0));