得到TMemo被选中文本的段落索引 ( 积分: 100 )

  • 主题发起人 主题发起人 LuckyJackie
  • 开始时间 开始时间
L

LuckyJackie

Unregistered / Unconfirmed
GUEST, unregistred user!
主要是想得到被选中文本的起始段落号与结束段落号
CLX中好像有对应属性property Selection: TMemoSelection;,VCL中没有
 
var
L1,L2:integer; //起始行号,结束行号。(第一行为0)
begin
L1:=SendMessage(memo1.Handle,EM_LINEFROMCHAR,Memo1.SelStart,0);
L2:=SendMessage(memo1.Handle,EM_LINEFROMCHAR,Memo1.SelStart+Memo1.SelLength,0);
end;
 
谢谢myid0602, 列号能得到吗?
 
LineNum:longint;
CharsBeforeLine:longint;
begin
行 LineNum:=SendMessage(Memo1.Handle,EM_LINEFROMCHAR,Memo1.SelStart,0);
列 CharsBeforeLine:=SendMessage(Memo1.Handle,EM_LINEINDEX,LineNum,0);
Label1.Caption:='Line'+IntToStr(LineNum+1);
Label2.Caption:='Position'+IntToStr((Memo1.SelStart-CharsBeforeLine)+1);
 

Similar threads

后退
顶部