Destacar linhas do RichEdit
07/08/2008
0
SelStart := Perform(EM_LINEINDEX, Linha, 0);
Simplesmente posiciona na primeira linha, independente do valor que coloque no lugar da Variavel ´Linha´.
Entao desenvolvi um procedimento que não acho o ideal, mas que resolveu em grande parte (codigo no final do topico). A cada mudanca no richedit (onChange) ele é reconfigurado, e só nao é perfeito porque o length NAO considera o ENTER na quebra de linha, entao, para cada ENTER sao duas posicoes erradas no SELSTART (pois considera o ENTER).
Alguma sugestão? Grato.
procedure TForm1.richChange(Sender: TObject);
var i, inicio, posicao: integer;
begin
posicao := rich.SelStart;
rich.SelStart := 0;
rich.SelLength := length(rich.Text);
rich.SelAttributes.Color := clBlack;
// Código que não funcionou
//rich.SelStart := Perform(EM_LINEINDEX, Linha, 0);
//rich.SelLength := length(rich.Text);
//rich.SelAttributes.Color := clRed;
// então trocado por este >>>
if (rich.Lines.Count > edLinha.Value) then
begin
inicio := 0;
i := 0;
while (i < edLinha.Value) do
begin
inicio := inicio + Length(rich.Lines[i]);
inc(i);
end;
rich.SelStart := inicio;
rich.SelLength := length(rich.Text) - inicio;
rich.SelAttributes.Color := clRed;
end;
rich.SelStart := posicao;
end;
Drf
Posts
07/08/2008
Marco Salles
Tente assim:
private { Private declarations } procedure RichClick(Sender: TObject);
no Oncreate do Form digite:
procedure TForm1.FormCreate(Sender: TObject); begin rich.ControlStyle := rich.ControlStyle + [csClickEvents]; Tform(rich).OnClick := richClick; end;
e na procedure escreva....
procedure TForm1.RichClick(Sender: TObject); var oldSelStart:integer; begin with rich do begin oldSelStart:=SelStart; SelStart := 0; SelLength := length(Text); SelAttributes.Color := clBlack; SelStart:=oldSelStart; SelLength := length(Text); SelAttributes.Color := clRed; end; end;
08/08/2008
Drf
Resumidamente o que preciso é que no momento que esteja alterando meu RichEdit, o texto da primeira e segunda linhas deverão ser pretos e os demais em vermelho.
Texto da primeira linha >>> preto
Texto da segunda linha >>> preto
Texto da terceira linha >>> vermelho
Texto da quarta linha >>> vermelho
...
Minha rotina acima funciona desde que não tenha ENTER dentro do RichEdit.
08/08/2008
Marco Salles
ai ja muda de Figura. São outros codigos
veja
private { Private declarations } procedure WmUser(var msg:Tmessage);message Wm_User;
var linha:integer;
procedure TForm1.richChange(Sender: TObject); begin if rich.Perform(EM_LINEFROMCHAR,rich.SelStart, 0) <> linha then postMessage(handle,wm_user,0,0); end;
procedure TForm1.WmUser(var msg: Tmessage); var oldSelStart:integer; begin with rich do begin onchange:=nil; oldSelStart:=SelStart; SelStart := 0; SelLength := length(text); SelAttributes.Color := clBlack; if lines.Count > 2 then begin SelStart := Perform(EM_LINEINDEX,2, 0); SelLength := length(Text); SelAttributes.Color := clRed; end; selStart:=oldSelStart; onChange:=richChange; Linha:=Perform(EM_LINEFROMCHAR,SelStart, 0); end; end;
08/08/2008
Drf
Quanto a minha afirmação que o codigo:
RichEdit.SelStart := Perform(EM_LINEINDEX, Linha, 0);
não funciona, estava parcialmente correto, pois ele apenas não funciona dentro dos eventos do próprio RichEdit.
Valeu.
Clique aqui para fazer login e interagir na Comunidade :)