Afficher des caracteres en exposant/indice dans un TRichedit

implementation
{$R *.DFM}
uses Richedit;

type
TCharacterFormat = (CFM_Superscript, CFM_Subscript, CFM_Normal);

procedure 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;
// 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: yOffset := 60;
CFM_Subscript: yOffset := -60;
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 TForm1.Button1Click(Sender: TObject);
begin
//Transforme les caractères sélectionnés en exposant
RE_SetCharFormat(RichEdit1, CFM_Superscript);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
//Transforme les caractères sélectionnés en indice
RE_SetCharFormat(RichEdit1, CFM_Subscript);
end;
Ajouter un commentaire
Pseudo
Adresse email
Site internet (optionnel)
Votre commentaire
Fiche de l'article
Mise a jour02/09/2002
VisualisationVu 1539 fois
PublicInternaute zz
CategorieDelphi - Trucs et astuces - Objet
Auteur de l'article
GIS L.L.C.,2000 GIS L.L.C.,2000
connecté le 02/11/2011
1 articles dans la section
Contacter l'auteur