| View previous topic :: View next topic |
| Author |
Message |
m_b Member
Joined: 23 Jun 2004 Posts: 15
|
Posted: 04/08/04 14:03 Post subject: Select a whole line in TSynEdit, TMemo or TRichEdit |
|
|
How can I select a whole line in TSynEdit, TMemo or TRichEdit if I've got it's index?
I know that I can use the SelStart and SelLength, but when I do that if the line is longer than the component width - the component scrolls to the end of the line, and this is really annoying to the user - he has to scroll back, what I want is to select the whole line without scrolling to the end of it. So, any suggestions???
m_b |
|
| Back to top |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 412 Location: Tehran, Iran
|
Posted: 04/08/04 15:09 Post subject: |
|
|
The following code may help you.
| Code: | function SelectLine(EditHandle: THandle; LineIndex: Integer; CaretInView: Boolean): Boolean;
var
LineStart: Integer;
LineLength: Integer;
begin
Result := False;
LineStart := SendMessage(EditHandle, EM_LINEINDEX, LineIndex, 0);
if LineStart >= 0 then
begin
LineLength := SendMessage(EditHandle, EM_LINELENGTH, LineStart, 0);
SendMessage(EditHandle, EM_SETSEL, LineStart, LineStart + LineLength);
if CaretInView then SendMessage(EditHandle, EM_SCROLLCARET, 0, 0);
Result := True;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if not SelectLine(Memo1.Handle, SpinEdit1.Value, False) then
ShowMessage('Line index out of bounds');
end; |
|
|
| Back to top |
|
 |
m_b Member
Joined: 23 Jun 2004 Posts: 15
|
Posted: 05/08/04 11:07 Post subject: |
|
|
| I'm sorry Kambiz, but this function does nothing, I've tried it with SynEdit and Memo, and nothing gets selected... Is there another way? |
|
| Back to top |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 412 Location: Tehran, Iran
|
Posted: 05/08/04 11:34 Post subject: |
|
|
I have no idea about SynEdit, but I'm sure the function works for TMemo and TRichEdit.
Maybe the HideSelection property of the memo is True, and you don't see the selection. |
|
| Back to top |
|
 |
m_b Member
Joined: 23 Jun 2004 Posts: 15
|
Posted: 05/08/04 16:18 Post subject: |
|
|
| You know, that may be possible, I'll check that and let you know if it worked... |
|
| Back to top |
|
 |
m_b Member
Joined: 23 Jun 2004 Posts: 15
|
Posted: 08/08/04 14:35 Post subject: |
|
|
| Yep, it works with memo & richedit, but not in synedit... Does anyone know how to get it to work with synedit? |
|
| Back to top |
|
 |
|