How to draw Unicode text?

How to draw Unicode text on TCustomControl? Are there any other options to do this without a canvas?

+6
source share
1 answer

Yes, you are there. However, I would recommend that you upgrade to Delphi 2009 or later, in which VCL has full Unicode support, and everything is much simpler.

Anyway, 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 older versions of Delphi (I think the code compiles in Delphi 7 on my Windows 95 virtual machine, but I don’t see the text. This is because Windows 95 is too old, I think.)

Update

If you want to support very old operating systems such as Windows 95 and Windows 98, you need to use TextOutW instead of DrawTextW , since the latter is not implemented (source) . TextOut less efficient than DrawText , so you need to calculate the position manually if you want, for example, to center the text inside the rectangle.

 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; 
+11
source

Source: https://habr.com/ru/post/887003/


All Articles