码迷,mamicode.com
首页 > 其他好文 > 详细

高亮 TRichEdit 当前行

时间:2015-01-07 14:30:58      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

var
  gStart, gLength, gCol: Integer;

procedure SetRichEdit(aRichEdit: TRichEdit);
var
  fRow, fCol: Integer;
  fStart, fLength, tStart: Integer;
begin
  fRow := aRichEdit.CaretPos.X;
  fCol := aRichEdit.CaretPos.Y;
  if gCol = fCol then Exit;
  if aRichEdit.SelLength > 0 then Exit;

  tStart := aRichEdit.SelStart;
  fStart := tStart - fRow;
  fLength := aRichEdit.Lines[fCol].Length;

  aRichEdit.Lines.BeginUpdate;

  if fLength > 0 then
  begin
    aRichEdit.SelStart := fStart;
    aRichEdit.SelLength := fLength;
    aRichEdit.SelAttributes.Color := clRed;
  end;

  if gLength > 0 then
  begin
    aRichEdit.SelStart := gStart;
    aRichEdit.SelLength := gLength;
//    aRichEdit.SelectAll;
    aRichEdit.SelAttributes.Color := clBlack;
  end;

  aRichEdit.SelStart := tStart;
  aRichEdit.SelLength := 0;

  aRichEdit.Lines.EndUpdate;

  gStart := fStart;
  gLength := fLength;
  gCol := fCol;
end;

procedure TForm1.RichEdit1Click(Sender: TObject);
begin
  SetRichEdit(TRichEdit(Sender));
end;

procedure TForm1.RichEdit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if Key in [37..40] then SetRichEdit(TRichEdit(Sender));
end;

高亮 TRichEdit 当前行

标签:

原文地址:http://www.cnblogs.com/pinksoft/p/4208141.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!