没有达到完全的居中,有明显的偏移,不知道问题出在什么地方,纠结
RectF rectTest;
rectTest.X = 100;
rectTest.Y = 100;
rectTest.Width = 200;
rectTest.Height = 200;
g.DrawRectangle(&Pen(Color(255,0,80,0),2),rectTest);
Font fontTEST(&fontFamily, 120, FontStyleItalic, UnitPixel);
stringFormat.SetAlignment(StringAlignmentCenter);
stringFormat.SetLineAlignment(StringAlignmentCenter);
g.DrawString(L"靠", 1, &fontTEST, rectTest, &stringFormat,&solidBrush);
我觉得吧问题是这样的:
g.DrawString的第三个参数,应该是CPoint的指针吧,你用CRect对么?(
如果是重载的话
楼主你的CRect(100,100,200,200),是从图片的左上角开始计算的。
第三个参数 是CPoint ,是有这个; 但是也有另外的重载函数啊, 用RectF没错! 目的是让 字 在自定义的框内!
rect.left = 100;
rect.top = 100;
rect.right = 300;
rect.bottom = 300;
dc.DrawFocusRect(&rect);
dc.DrawText(L"中",1,&rect,DT_SINGLELINE | DT_CENTER | DT_VCENTER); 但是 我想换GDI+ , 查了下函数 暂时没发现什么毛病 ,
以下设置,起到了 貌似居中的作用(有明显偏移啊)
stringFormat.SetAlignment(StringAlignmentCenter);
stringFormat.SetLineAlignment(StringAlignmentCenter);