Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting a whole line in a TRichEdit 1

Status
Not open for further replies.

jvff

Programmer
Apr 1, 2001
64
BR
Hello,
How do I select an entire line from a TRichEdit and change it's font? ThanQ, ;-)

JVFF (Janito Vaqueiro Ferreira Filho)
 
This is how I change the attributes of an entire line in a TRichEdit. I am sure there is a better way but this works for me.

First, I insert a marker in the RichEdit at the start of the line I wish to change.

This marker must be unique and must not occur anywhere else in the RichEdit.

I then set SelStart to the start of the marker and set SelLength to the length of the line.

I then change the attributes of the selected area.

Finally, I remove the marker.

Here is some sample code to change the font in line 3 to Arial.
Code:
procedure ChangeLineToArial ( line: integer );
const
  Marker = '/~^&"£$';
var
  p: integer;  
begin  
  with RichEdit1 do begin
    Assert ( Pos ( marker, Text ) = 0 );
    Lines[line] := Marker + Lines[line];
    SelStart := Pos ( Marker, Text ) - 1;
    SelLength := Length ( Lines[line] );
    SelAttributes.Name := 'Arial';
    p := Pos ( Marker, Lines[line] );
    Lines[line] := Copy ( Lines[line], 1, p-1 ) + Copy ( Lines[line], p+Length(Marker), Length(Text) );
  end;
end;

Andrew
 
If you know the text, you can use the search funtions to highlight it in the richedit (example in the Delphi Help), then use API calls to get the line number (if you need to). Then continue as towerbase suggests.

This gets the Row (Line) and col position of seleted text

CharPos.Y := SendMessage(Editor.Handle, EM_EXLINEFROMCHAR, 0, Editor.SelStart);
CharPos.X := (Editor.SelStart -
SendMessage(Editor.Handle, EM_LINEINDEX, CharPos.Y, 0));


Steve


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top