procedure TForm1.RE_SetCharFormat(RichEdit: TRichEdit;
CharacterFormat: TCharacterFormat);
var
// The CHARFORMAT structure contains information about
// character formatting in a rich edit control.
Format: TCharFormat;
begin
FillChar(Format, SizeOf(Format), 0);
with Format do
begin
cbSize := SizeOf(Format);
dwMask := CFM_OFFSET or CFM_SIZE or CFM_COLOR;
// Character offset, in twips, from the baseline.
// If the value of this member is positive,
// the character is a superscript;
// if it is negative, the character is a subscript.
case CharacterFormat of
CFM_Superscript:
begin
yOffset := 60;
yHeight := 200;
crTextColor := clGreen;
end;
CFM_Subscript:
begin
yOffset := -60;
yHeight := 200;
crTextColor := clBlue;
end;
CFM_Normal:
begin
yOffset := 0;
crTextColor := clBlack;
end;
end;
end;
// The EM_SETCHARFORMAT message sets character formatting in a rich edit control.
// SCF_SELECTION: Applies the formatting to the current selection
Richedit.Perform(EM_SETCHARFORMAT, SCF_SELECTION, Longint(@Format));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
RE_SetCharFormat(RichEdit1, CFM_Superscript);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
RE_SetCharFormat(RichEdit1, CFM_Subscript);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
RE_SetCharFormat(RichEdit1, CFM_Normal);
end;