Delphi高亮显示TRichEdit当前行


本文整理自网络,侵删。

 
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;

相关阅读 >>

Delphi 取得和设置当前系统的短日期格式

Delphi 通过指点操作获得窗口句柄

Delphi xe android]获取屏幕的物理分辨率

Delphi字符串加密解密

Delphi xe webbroker 开发,解决 response 返回中文乱码问题

Delphi窗体置顶

Delphi inputquery

Delphi 为richedit设置行号

Delphi百度网盘真实地址解析

Delphi 如何获得其他进程的token

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...