I
import
Unregistered / Unconfirmed
GUEST, unregistred user!
Delphi中有控件MEMO,当使用应控件输入内容或编辑时,如何确定光标当前的位置呢?这时就可以调用WINDOWS API中的EM_LINEFROMCHAR和EM_LINEINDEX消息来确定MEMO控件中光标的当前行和列,具体调用方法的过程如下:
procedure TForm1.Button1Click(Sender: TObject);
var
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);
end;
//另一种方法
procedure TForm1.Button1Click(Sender: TObject);
var
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);
end;
//另一种方法