关于RichEdit中如何实现光标定位到X行Y列的实现方法?(50分)

  • 主题发起人 主题发起人 TW_GD
  • 开始时间 开始时间
T

TW_GD

Unregistered / Unconfirmed
GUEST, unregistred user!
关于RichEdit中如何实现光标定位到X行Y列的实现方法?
 
可以用richedit.selstart进行定位
 
顶行设定:
procedure TSRichEdit.SetTopLine(Value: integer);
{Put selected line at top of memo}
var
tl: integer;
begin
tl := Value;
if tl < 0 then tl := 0;
if tl > Lines.Count - 1 then tl := Lines.Count - 1;
SendMessage(Handle, EM_LINESCROLL, 0, tl - SendMessage(Handle, EM_GETFIRSTVISIBLELINE, 0, 0));
end;

光标定位到某一行:
procedure TSRichEdit.SetCurrentLine(Value: integer);
{Put caret on start of selected line}
var
cl: integer;
begin
cl := Value;
{Restrict range to available lines}
if cl < 0 then cl := 0;
if cl > Lines.Count - 1 then cl := Lines.Count - 1;
SelLength := 0;
SelStart := SendMessage(Handle, EM_LINEINDEX, cl, 0);
end;

光标定位到某一列:
procedure TSRichEdit.SetCurrentPosition(Value: integer);
var
cl: integer;
cp: integer;
begin
cl := GetCurrentLine;
cp := Value;
if cp < 0 then cp := 0;
if (cp > Length(Lines[cl])) then cp := Length(Lines[cl]);
{Put caret in selected position}
SelLength := 0;
SelStart := SendMessage(Handle, EM_LINEINDEX, cl, 0) + cp;
end;
光标定位到指定的坐标点 richedit1.Perform(WM_LBUTTONDOWN, MK_LBUTTON, MakeLong(X, Y))


 
感谢两位,尤其是tianhf.
 
后退
顶部