如何绘制Unicode文本? [英] How do I draw Unicode text?

查看:148
本文介绍了如何绘制Unicode文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在TCustomControl上绘制Unicode文字?有没有其他选项,使它没有画布?

解决方案

是的,你是现场。仍然,我建议您升级到Delphi 2009或更高版本,其中VCL具有完整的Unicode支持,一切都更容易。



无论如何,你可以做

 过程TMyControl.Paint; 
var
S:WideString;
r:TRect;
begin
inherited;
r:= ClientRect;
S:='这是积分符号:'#$ 222b;
DrawTextW(Canvas.Handle,PWideChar(S),length(S),r,DT_SINGLELINE或
DT_CENTER或DT_VCENTER或DT_END_ELLIPSIS);
end;

在Delphi的旧版本中我的代码在我的虚拟Windows 95机器,但我看不到文字,这是因为Windows 95太旧了,我想。)



更新 b

如果你想支持非常老的操作系统,如Windows 95和Windows 98,你需要使用 TextOutW ,而不是 DrawTextW ,因为后者未实现(源) TextOut DrawText 不够强大,所以你需要手动计算位置,

 过程TMyControl.Paint; 
var
S:WideString;
begin
inherited;
S:='这是积分符号:'#$ 222b;
TextOutW(Canvas.Handle,0,0,PWideChar(S),length(S));
end;


How to draw Unicode text on TCustomControl? Are there other options to make it without the Canvas?

解决方案

Yes, you are right on spot. Still, I would recommend you to upgrade to Delphi 2009 or later in which the VCL has full Unicode support and everything is much easier.

Anyhow, you can do

procedure TMyControl.Paint;
var
  S: WideString;
  r: TRect;
begin
  inherited;
  r := ClientRect;
  S := 'This is the integral sign: '#$222b;
  DrawTextW(Canvas.Handle, PWideChar(S), length(S), r, DT_SINGLELINE or
    DT_CENTER or DT_VCENTER or DT_END_ELLIPSIS);
end;

in old versions of Delphi (I think. The code compiles in Delphi 7 in my virtual Windows 95 machine, but I see no text. That is because Windows 95 is too old, I think.)

Update

If you want to support very old operating systems, like Windows 95 and Windows 98, you need to use TextOutW instead of DrawTextW, since the latter isn't implemented (source). TextOut is less powerful then DrawText, so you need to compute the position manually if you want to center the text inside a rectangle, for instance.

procedure TMyControl.Paint;
var
  S: WideString;
begin
  inherited;
  S := 'This is the integral sign: '#$222b;
  TextOutW(Canvas.Handle, 0, 0, PWideChar(S), length(S));
end;

这篇关于如何绘制Unicode文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆