在vs。net2003中 利用gid+ 绘制文字 现在需要在指定的矩形框的中心显示文字,程序如下: Font myFont(L"Arial", 20); 
SolidBrush myBrush1(fcolor); StringFormat *sFmat=new StringFormat( )
sFmat->SetLineAlignment(StringAlignmentCenter);
sFmat->SetAlignment(StringAlignmentCenter);

RectF testRect(x1,y1,200,50);
string aa="测试";
gDC->DrawRectangle(myPen,testRect);
gDC->DrawString( ToWChar(aa.c_str()) , 11, &myFont, testRect, sFmat,&myBrush1);但是效果没有达到预期,显示一直靠左,请教为什么,谢谢

解决方案 »

  1.   

    DrawText(m_str, TitleRect, nStyle);
    对应TitleRect进行裁剪
      

  2.   

    同意一楼。pDC->DrawText("ABCDE", &rcTextArea, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
      

  3.   

    设置要输出的矩形RECT,格式设为DT_CENTER | DT_VCENTER就可以了。如果偏了是矩形的位置不对。
      

  4.   

    继续等 gdi+ 啊 
      

  5.   

    前面的代码没什么错,关键是最后一句
    gDC->DrawString( ToWChar(aa.c_str()) , 11, &myFont, testRect, sFmat,&myBrush1); 这个11是什么意思,应该是字符串的长度啊,以这个字符串来看,应该是2,或者写成wcsstr(ToWChar(aa.c_str()) )