问一个GDI+问题GdipDrawString的显示字体位置问题?
GdipCreateFontFamilyFromName StrPtr(fontname), 0, ffamily
GdipCreateStringFormat 0, 0, fformat
GdipStringFormatGetGenericTypographic fformat
GdipSetStringFormatLineAlign fformat, StringAlignmentCenter
GdipSetStringFormatAlign fformat, 0'左对齐
rclayout.Left = 0
rclayout.Top = 0
rclayout.Right = 400
rclayout.Bottom =400
GdipCreateSolidFill &HF7FFFFFF, texturebrush
GdipCreateFont ffamily, fontsiz, FontStyle.FontStyleBold, UnitPixel, textfont
GdipDrawString Graphics, StrPtr("中国人"), -1, textfont, rclayout, fformat, texturebrush
上面代码执行后,显示的"中国人"的右边对齐老不是在400的像素位置,怎么回事啊?
添加了GdipStringFormatGetGenericTypographic fformat还是不行啊。
麻烦知道的朋友帮忙解释一下,如何改进我的代码,使我的"中国人"显示以400像素位置的右边靠齐;
还有,如果我想把“中国人”以最大字体在0,0,400,400区域居中水平显示,应该怎么实现。
先谢谢了!
[解决办法]
'************************************************************************************************************************'函数功能:按照一定的格式书写文字,正常排列(不包括:旋转、描边等)'参数说明:strFontName:字体名称' :lngFontColor:文字颜色' :stringAlignMode:对齐方式' :sngFontSize:字体大小' :lngFontStyle:字体样式(粗体、斜体..)' :DrawUnit:绘图单元' :TextRenderMode:文本渲染模式' :lngLeft:绘制文本区域 Left' :lngTop:绘制文本区域 Top' :lngWidth:绘制文本区域 Width' :lngHeight:绘制文本区域 Height' :strText:要书写的文本'返回说明:成功:True 失败:False'************************************************************************************************************************Public Function DrawNormalText(ByVal strFontName As String, ByVal lngFontColor As Long, _ ByVal StringAlignMode As StringAlignment, _ ByVal sngFontSize As Single, ByVal lngFontStyle As Long, _ ByVal DrawUnit As GpUnit, ByVal TextRenderMode As TextRenderingHint, _ ByVal lngLeft As Long, ByVal lngTop As Long, _ ByVal lngWidth As Long, ByVal lngHeight As Long, ByVal strText As String) As Boolean Dim gpP As GpStatus Dim lngCurFont As Long Dim rclayout As RECTFOn Error GoTo errFun gpP = GdipCreateFontFamilyFromName(strFontName, 0, lngFontFamily) gpP = GdipCreateStringFormat(0, 0, lngStringFormat) gpP = GdipCreateSolidFill(lngFontColor, lngSolidBrush) gpP = GdipSetStringFormatAlign(lngStringFormat, StringAlignMode) gpP = GdipCreateFont(lngFontFamily, sngFontSize, lngFontStyle, DrawUnit, lngCurFont) gpP = GdipSetTextRenderingHint(lngGraphics, TextRenderMode) With rclayout .Left = lngLeft .Top = lngTop .Width = lngWidth .Height = lngHeight End With gpP = GdipDrawString(lngGraphics, strText, -1, lngCurFont, rclayout, lngStringFormat, lngSolidBrush) gpP = GdipDeleteFontFamily(lngFontFamily) gpP = GdipDeleteStringFormat(lngStringFormat) gpP = GdipDeleteFont(lngCurFont) gpP = GdipDeleteBrush(lngSolidBrush) lngSolidBrush = 0 lngFontFamily = 0 If IsNull(gpP) Then DrawNormalText = False Else DrawNormalText = True End If Exit FunctionerrFun: DrawNormalText = FalseEnd Function