有关memo的简单问题(100分)

  • 主题发起人 主题发起人 rsw
  • 开始时间 开始时间
R

rsw

Unregistered / Unconfirmed
GUEST, unregistred user!
请问在Tmemo(或TRichedit)中,如何得到当前的光标在何处????
指当前字所所处的坐标位置,不是鼠标的位置。
 
procedure TForm1.Button1Click(Sender: TObject);
var
i,j :integer;
begin
getxy(i,j);
ShowMessage(Format('row=%d,col=%d',[i,j]));
end;

procedure TForm1.getxy(var i,j :integer);
var
iIndex :Integer;
begin
i := SendMessage(Memo1.handle,em_lineFromChar,-1,0);
iindex :=SendMessage(Memo1.handle,em_lineindex,i,0);
j := Memo1.selstart+Memo1.SelLength-iindex;
end;
是以前从已答问题中抄下来的.很好.
 
用TMemo->CaretPos即可
 
iLine := Memo1.Perform(em_LineFromChar, $FFFF, 0);
iRow := Memo1.Perform(em_PosFromChar, $FFFF, 0);
 
The following description is copied from help.

TMemo->CaretPos

Indicates the position of the caret in the client area of
the memo.

__property Windows::TPoint CaretPos = {read=GetCaretPos};


Use CaretPos to determine the coordinates of the cursor.
CaretPos indicates the X and Y position (in terms of lines and characters) relative to the client origin of the memo.

To determine the position of the caret in terms of characters of
text only (rather than X/Y location), use the SelStart property.
 
啊,有错,下面的可以使 :-) C++Builder

TPoint Point; GetCaretPos(&Point); DWORD both;
both = Memo1->Perform(EM_CHARFROMPOS, 0, MAKELPARAM(Point.x, Point.y));
int indexLine = HIWORD(both);
int indexLength = LOWORD(both) - Memo1->Perform(EM_LINEINDEX, -1, 0);
indexLine++; indexLength++; char RowCol[10] = " ";
sprintf(RowCol, "%d:%d", indexLine, indexLength);
StatusBar1->Panels->Items[4]->Text = RowCol;
 
大家都没明白我的意思,我是想得到当前的字所处的坐标,要以象素为单位。
并不是当前的行数,列数,而是当前的象素的坐标。

 
是挺困难的。
 
我也想知道答案.
 
多人接受答案了。
 
srw, rsw, wrs , www 你(们) 想捣乱吗?
 
后退
顶部