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区域居中水平显示,应该怎么实现。
先谢谢了!
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区域居中水平显示,应该怎么实现。
先谢谢了!
解决方案 »
- vb 怎样实现傲游浏览器状态栏那种效果(冷笑话的)
- 用MSComm控件做串口通信程序,是RS232转485通信,平时正常,但加了干扰后,出现"...8005.."的错误??然后电脑需重启动。
- 一年中的第22周开始的日期是多少?
- 软件界面开发
- vb中的线程问题
- ******如何用API在屏幕最上层画红色的线?*******谁最快解决给谁30分
- 请教:MSComm1.InputMode = comInputModeBinary……
- 请问在vb中怎样用文本框给一维数组赋值?(急!!!!)
- vb数据库!
- visual basic 6.0 中如何将在多个picturebox 中绘制的图像保存成一张图片或pdf文本
- 求教下VB mshart方面的问题
- 实时错误'7005':行设置不可用
'************************************************************************************************************************
'函数功能:按照一定的格式书写文字,正常排列(不包括:旋转、描边等)
'参数说明: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 RECTF
On 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 Function
errFun:
DrawNormalText = False
End Function
我显示是没问题,就是位置偏移了。
http://blog.sina.com.cn/s/blog_6a2787970100k6ws.html
我主要问题是位置偏移了,不是我的代码无法显示文本。
谢谢了,麻烦能不能用MeasureString我调试到最终结果,再来实现显示文本啊。
但是.MeasureString获取出来的区域也不对啊,left和right有的是负数的。
晕