Tema: richedit
Ver Mensaje Individual
  #10  
Antiguo 26-05-2010
Avatar de José Luis Garcí
[José Luis Garcí] José Luis Garcí is offline
Miembro Premium
 
Registrado: may 2003
Ubicación: Las Palmas de G.C.
Posts: 1.372
Reputación: 23
José Luis Garcí Va camino a la fama
Te pongo el código que uso para lo siguiente

Código Delphi [-]

procedure TFprincipal.ColorBox2Click(Sender: TObject);
//-------------------------------------------------------------------------------
//***********************************************[color del fondo]****
//-------------------------------------------------------------------------------
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);
//-------------------------------------------------------------------------------
//*****************************************************[ELEGIMOS COLOR texto]****
//-------------------------------------------------------------------------------
begin
redtrededitcion.SelAttributes.Color := ColorBox1.Selected;
end;

procedure TFprincipal.btn5Click(Sender: TObject);
//-----------------------------------------------------------------------------
//**************************************************[ Justificar Texto  ]******
//-----------------------------------------------------------------------------
begin
   if Length(redtrededitcion.selText)>0 then JustifyRichEdit(redtrededitcion,FAlse)
                                        else JustifyRichEdit(redtrededitcion,True);
end;


// AllText : True=todo o texto; False=parágrafo atual
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));
// Restaura seleção caso tenhamos mudado para All
    RichEdit.SelStart := SelStart;
    RichEdit.SelLength := SelLength;
  end;
end;

procedure TFprincipal.ColorBox3Change(Sender: TObject);
//-----------------------------------------------------------------------------
//*****************************************[ Color de Fondo del Editor  ]******
//-----------------------------------------------------------------------------
begin
   redtrededitcion.Color:=ColorBox3.Selected;
end;

Espero os sirva
__________________
Un saludo desde Canarias, "El abuelo Cebolleta"
Responder Con Cita