admin

[应用技巧] delphi 单击TMemo选择光标所在行,并显示行号

procedure SelectMemoLine(Memo : TCustomMemo) ;
var
Line : integer;
begin
with Memo do
begin
Line := Perform(EM_LINEFROMCHAR, SelStart, 0) ;
SelStart := Perform(EM_LINEINDEX, Line, 0) ;
SelLength := Length(Lines[Line]) ;
end;
end;

//Usage: 
procedure TForm1.Memo1Click(Sender: TObject) ;
begin
SelectMemoLine(Memo1) ;
end; 



procedure TForm1.mmo1Click(Sender: TObject);

begin

  SelectMemoLine(Mmo1);

  mjb:=mmo1.Handle;

end;


//获取行号

SendMessage(Mmo1.Handle,EM_LINEFROMCHAR,Mmo1.SelStart,0)

#1楼
发帖时间:5月前   |   查看数:0   |   回复数:0
游客组