Te pongo el código que uso para lo siguiente
Código Delphi
[-]
procedure TFprincipal.ColorBox2Click(Sender: TObject);
var
Format: CHARFORMAT2;
begin
FillChar(Format, SizeOf(Format), 0);
with Format do
begin
cbSize := SizeOf(Format);
dwMask := CFM_BACKCOLOR;
crBackColor := ColorBox2.Selected;
redtrededitcion.Perform(EM_SETCHARFORMAT, SCF_SELECTION, Longint(@Format));
end;
end;
procedure TFprincipal.ColorBox1Click(Sender: TObject);
begin
redtrededitcion.SelAttributes.Color := ColorBox1.Selected;
end;
procedure TFprincipal.btn5Click(Sender: TObject);
begin
if Length(redtrededitcion.selText)>0 then JustifyRichEdit(redtrededitcion,FAlse)
else JustifyRichEdit(redtrededitcion,True);
end;
procedure JustifyRichEdit(RichEdit :TRichEdit; AllText :Boolean);
const
TO_ADVANCEDTYPOGRAPHY = $1;
EM_SETTYPOGRAPHYOPTIONS = (WM_USER + 202);
EM_GETTYPOGRAPHYOPTIONS = (WM_USER + 203);
var
ParaFormat :TParaFormat;
SelStart,
SelLength :Integer;
begin
ParaFormat.cbSize := SizeOf(ParaFormat);
if SendMessage(RichEdit.handle,
EM_SETTYPOGRAPHYOPTIONS,
TO_ADVANCEDTYPOGRAPHY,
TO_ADVANCEDTYPOGRAPHY) = 1 then
begin
SelStart := RichEdit.SelStart;
SelLength := RichEdit.SelLength;
if AllText then
RichEdit.SelectAll;
ParaFormat.dwMask := PFM_ALIGNMENT;
ParaFormat.wAlignment := PFA_JUSTIFY;
SendMessage(RichEdit.handle, EM_SETPARAFORMAT, 0, LongInt(@ParaFormat));
RichEdit.SelStart := SelStart;
RichEdit.SelLength := SelLength;
end;
end;
procedure TFprincipal.ColorBox3Change(Sender: TObject);
begin
redtrededitcion.Color:=ColorBox3.Selected;
end;
Espero os sirva