uses RichEdit;
procedure SetSubscript(ARichEdit: TCustomRichEdit; Sub, ASize: Integer);
//Sub: 0:无 1:上标 -1:下标
//ASize:正常的字体大小
var
Format: TCharFormat;
procedure InitFormat(var Format: TCharFormat);
begin
FillChar(Format, SizeOf(TCharFormat), 0);
Format.cbSize := SizeOf(TCharFormat);
end;
procedure SetAttributes(var Format: TCharFormat);
begin
if ARichEdit.HandleAllocated then
SendMessage(ARichEdit.Handle, EM_SETCHARFORMAT, SCF_SELECTION, LPARAM(@Format))
end;
begin
InitFormat(Format);
with Format do
case Sub of
0:
begin
dwMask := Integer(CFM_OFFSET + CFM_SIZE);
yHeight := ASize * 20;
Format.yOffset := 0;
end;
1:
begin
dwMask := Integer(CFM_OFFSET + CFM_SIZE);
yHeight := ASize * 2 div 3 * 20;
Format.yOffset := ASize div 4 * 20;
end;
-1:
begin
dwMask := Integer(CFM_OFFSET + CFM_SIZE);
yHeight := ASize * 2 div 3 * 20;
Format.yOffset := -ASize div 4 * 20;
end;
else
Exit;
end;
SetAttributes(Format);
end;