Trichedit中!!!分很容易赚的(第一个回答队的得全部的分)(200分)

  • 主题发起人 主题发起人 yanggu
  • 开始时间 开始时间
Y

yanggu

Unregistered / Unconfirmed
GUEST, unregistred user!
在TRICHEDIT中MOUSEMOVE()事件中,如何根据
鼠标的坐标得到当前位置的字符的行和列,scrollbars
为both,

 
你要的api 资料
http://wjiachun.edu.chinaren.com/down/apihelp.zip
 
procedure TForm1.RichEdit1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
mpt: TPoint;
cr, ccr: TCharRange;
i: Integer;
CharPos: TPoint;
begin
i := SendMessage(RichEdit1.Handle, EM_EXGETSEL, 0, longInt(@ccr));
mpt.x := x;
mpt.y := y;
i := SendMessage(RichEdit1.Handle, EM_CHARFROMPOS, 0, LongInt(@mpt));
cr.cpmin := i;
cr.cpMax := i;
i := SendMessage(RichEdit1.Handle, EM_EXSETSEL, 0, longInt(@cr));
CharPos.Y := SendMessage(RichEdit1.Handle, EM_EXLINEFROMCHAR, 0,
RichEdit1.SelStart);
CharPos.X := (RichEdit1.SelStart -
SendMessage(RichEdit1.Handle, EM_LINEINDEX, CharPos.Y, 0));
Inc(CharPos.Y);
Inc(CharPos.X);
Caption := Format('Line: %3d Col: %3d', [CharPos.Y, CharPos.X]);
i := SendMessage(RichEdit1.Handle, EM_EXSETSEL, 0, longInt(@ccr));
end;
 
在RichEdit的OnSelectionChange事件处理过程中加入适当的代码可以实时
地获得当前光标位置,示例如下:

procedure TForm1.RichEdit1SelectionChange(Sender: TObject);
var
X, Y: LongInt;
begin
Y := SendMessage(RichEdit1.Handle, EM_LINEFROMCHAR,
RichEdit1.SelStart, 0);
X := RichEdit1.SelStart;
SendMessage(RichEdit1.Handle, EM_LINEINDEX, Y, 0);
Inc(Y); // 光标的行号
Inc(X); // 光标的列号
end;
 
tcharrange 如何定义
 
uses RichEdit;
 
your answer is right,my E_mail is yh_01@163.net there is two
handreds fen for you!!!
 
后退
顶部