uses Winapi.RichEdit; // yOffset values typeTCharacterFormat = (CFM_Superscript, CFM_Subscript, CFM_Normal); procedure RE_SetCharFormat(RichEdit: TRichEdit; CharacterFormat: TCharacterFormat); //======================================= procedure RE_SetCharFormat(RichEdit: TRichEdit; CharacterFormat: TCharacterFormat); var// The CHARFORMAT structure contains information about// character formatting in a rich edit control. Format: TCharFormat; beginFillChar(Format, SizeOf(Format), 0);with Format dobegincbSize := SizeOf(Format);dwMask := CFM_OFFSET;// 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 ofCFM_Superscript: yOffset := 250; //上标偏移值CFM_Subscript: yOffset := -250; //下标偏移值CFM_Normal: yOffset := 0;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 TMainForm.ToolButton7Click(Sender: TObject); begin RE_SetCharFormat(Editor, CFM_Superscript); //上标 end;procedure TMainForm.ToolButton8Click(Sender: TObject); begin RE_SetCharFormat(Editor, CFM_Subscript); //下标 end;


