Oli Howson
Oli Howson

Reputation: 43

Delphi XE - SynMemo - highlight a line and stop the cursor going where you click it

I'm using Delphi XE today (one of four versions I play with :)

I've installed SynEdit/SynMemo to replace the standard TMemo.

(a) I want to highlight a whole line based on its line number. (b) When I click on the first line, I want the caret to go to the start of the line not appear where I click - more like notepad than a code editor.

Any help much appreciated!

Upvotes: 1

Views: 1009

Answers (1)

Wodzu
Wodzu

Reputation: 6989

To highlight a specific line you need to use OnSpecialLineColors event.

Try this code:

procedure TfrmMain.SynMemo1SQLSpecialLineColors(Sender: TObject; Line: Integer;
  var Special: Boolean; var FG, BG: TColor);
begin
  // Change highlight for the first line.
  if Line = 1 then
  begin
    BG := clBlack;
    FG := clGreen;
  end;
end;

Also, make sure that Highlighter property is not set, otherwise it might override your highlighting.

Upvotes: 2

Related Questions