gpt4 book ai didi

delphi - 如何绘制 Unicode 文本?

转载 作者:行者123 更新时间:2023-12-03 14:51:56 24 4
gpt4 key购买 nike

如何在TCustomControl上绘制Unicode文本?是否有其他选项可以在没有 Canvas 的情况下实现它?

最佳答案

是的,你说得对。尽管如此,我还是建议您升级到 Delphi 2009 或更高版本,其中 VCL 具有完整的 Unicode 支持,一切都会变得更加容易。

无论如何,你都可以

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;

在旧版本的 Delphi 中(我认为。代码在我的 Windows 95 虚拟机中的 Delphi 7 中编译,但我看不到任何文本。我认为这是因为 Windows 95 太旧了。)

更新

如果您想支持非常旧的操作系统,例如 Windows 95 和 Windows 98,则需要使用 TextOutW 而不是 DrawTextW,因为后者尚未实现(source)TextOut 的功能不如 DrawText 强大,因此,例如,如果您想将文本置于矩形内居中,则需要手动计算位置。

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;

关于delphi - 如何绘制 Unicode 文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5840719/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com