SynEdit 鼠标点击行号栏自动选中所在行

//CaretX  光标或鼠标所在行的列号(第几列),从0开始计数
//CaretY  光标或鼠标所在行的行号(第几行),从0开始计数
//SynEdit.Lines.Strings[]下标从0开始。要CaretY-1   设置LineNumberStart=0没用。
procedure TfrmLogin.sqlTextGutterClick(Sender: TObject; Button: TMouseButton; X, Y, Line: Integer; Mark: TSynEditMark);
begin
  // ShowMessage(Format('CaretX:%d;CaretY:%d'+#13+'Line_Text:[%s]',[sqlText.CaretX,sqltext.CaretY,sqlText.Lines.Strings[sqltext.CaretY-1]]));
 { Memo控件可以采用下面的方法选中指定行,SynEdit无效,只能选中第一行。
   sqlText.SelStart := SendMessage(sqlText.Handle, EM_LINEINDEX, sqltext.CaretY - 1, 0);
   sqlText.SelLength := Length(sqlText.Lines[sqltext.CaretY - 1]);  }
   sqlText.SelLength := Length(sqlText.Lines.Strings[sqltext.CaretY-1]); //选中该行
end;

 

Memo 当前行号,坐标,位置

可以使用Memo的属性CaretPos.X来取行鼠标所在行的行数与鼠标所在行的第几位

Memo.CaretPos.X 光标或鼠标所在行的列号(第几位),从0开始计数
Memo.CaretPos.Y 光标或鼠标所在行的行号(位于Memo的第几行),从0开始计数

 

TBufferCoord  bc=synEditor1->CaretXY;

synEditor1->CaretX;
synEditor1->CaretY;

posted @ 2022-10-04 00:15  IT情深  阅读(39)  评论(0编辑  收藏  举报