获取字符串宽度,而不是用len()获取字符个数,请知道的朋友教一下,不论用什么方法,只要能实现就可以了。
------解决方案--------------------
- SQL code
//====================================================================// 事件: of_getsize()//--------------------------------// 描述://--------------------------------// 参数:// value window aw 窗口// value datawindow adw 数据窗口// value long al_row 行// value string as_col 列名// reference integer ai_width 宽// reference integer ai_height 高//--------------------------------// 返回: integer//--------------------------------// 修改历史:////====================================================================Int li_height, li_widthString ls_text, ls_fontface, ls_fontsize, ls_weight, ls_italic, ls_underlineBoolean lb_italic, lb_underlinels_text = adw.GetItemString(al_row, as_col)IF IsNull(ls_text) Or Len(ls_text) = 0 THEN RETURN -1ls_fontface = adw.Describe(as_col + '.font.face')ls_fontsize = adw.Describe(as_col + '.font.height')ls_weight = adw.Describe(as_col + '.font.weight')ls_italic = adw.Describe(as_col + '.font.italic')ls_underline = adw.Describe(as_col + '.font.underline')IF ls_italic = '1' THEN lb_italic = TrueELSE lb_italic = FalseEND IFIF ls_underline = '1' THEN lb_underline = TrueELSE lb_underline = FalseEND IFInteger li_Len, li_Return, li_WM_GETFONT = 49 // hex 0x0031ULong lul_Hdc, lul_Handle, lul_hFontStaticText lst_tempsize lstr_SizeIF IsNull(aw) Or Not IsValid (aw) THEN RETURN -1li_Return = aw.OpenUserObject(lst_temp)IF li_Return = 1 THEN lst_temp.FaceName = ls_fontface lst_temp.TextSize = Integer(ls_fontsize) lst_temp.Weight = Integer(ls_weight) lst_temp.Italic = lb_italic lst_temp.Underline = lb_underline lst_temp.width = 700 li_Len = Lena(ls_text) lul_Handle = Handle(lst_temp) lul_Hdc = GetDC(lul_Handle) lul_hFont = Send(lul_Handle, li_WM_GETFONT, 0, 0) SelectObject(lul_Hdc, lul_hFont) IF Not GetTextExtentpoint32A(lul_Hdc, ls_text, li_Len, lstr_Size ) THEN aw.CloseUserObject(lst_temp) RETURN -1 END IF ai_Width = PixelsToUnits ( lstr_Size.l_cx, XPixelsToUnits! ) ai_Height = PixelsToUnits ( lstr_Size.l_cy, YPixelsToUnits! ) // long ll_sp// ll_sp = long(UnitsToPixels ( (700 - ai_width)/(li_len - 1), XUnitsToPixels!))// SetTextCharacterExtra(lul_hdc, ll_sp)// TextOut(lul_hdc, ls_text) ReleaseDC(lul_Handle, lul_Hdc) // lst_temp.width = ai_width lst_temp.height = ai_height lst_temp.Text = ls_text lst_temp.Show()// li_Return = aw.CloseUserObject(lst_temp)END IFRETURN li_Return