Re:TRichEdit - subscripts, superscripts ?
Quote
In article <3a6df554_1@dnews>, Ivan Voutchkov wrote:
> Is it possible to display subscripts and superscripts with TRichEdit? For
> instance I want to write x^2 or sqr(x), in a proper science way ?
Well, yes and no <g>. You have to use a little API here since the
TTextAttributes class used to implement DefAttributes does not surface this
ability (since it was designed to be compatible to TFont).
You should be able to set sub/superscripts by sending an EM_SETCHARFORMAT
message to a TRichedit. Something like this:
Var
format: TCharFormat; { defined in Unit RichEdit }
FillChar( format, sizeof(format), 0);
With format Do Begin
cbSize:= Sizeof(format);
dwMask:= CFM_OFFSET;
yOffset:= 60; { superscript by 60 twips, negative values give
subscripts}
End;
richedit1.Perform( EM_SETCHARFORMAT, SCF_SELECTION,
LongInt(@format));
The message affects the current selection. If there is none it will affect
new text inserted via seltext.
The problem here is that the rich edit common control version 1 does not
adjust the line spacing properly when you add sub- or superscripted text to
a line, the text may be cut off at the top or bottom. This version of the
control also has no way to manually adjust the linespacing. There are
wrappers for version 2 and 3 of the control around, e.g. the TRxrichEdit
component in RXLib. These versions handle sub/superscripted text correctly
but they require riched20.dll on the target system and it may not be
present on all of them.
Peter Below (TeamB) 100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: Till Feb.2001 i will only visit the groups on weekends, so be
patient if i don't reply immediately.