顶行设定:
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));
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));
Editor.SelStart:=chars;
Editor.SelLength:=length(Editor.Lines.Strings[i]);
SendMessage(Handle, EM_LINEINDEX, line,0);
Editor.SetFocus;
PostMessage(Editor.Handle,EM_SCROLLCARET,0,0);
如果光标所在的行在控件显示范围之外,我想让他自动滚动到可视范围内,我这样写不管用,应该怎样写呢?
你可以调用WINDOWSAPI中的EM-LINEFROMCHAR和EM-LINEINDEX函数来确定MEMO控件中的当前行和列,具体调用的过程见下面 的过程。varLineNum:longint;CharsBeforeLine:longint;beginLineNumΚ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;
RichEdit1.CaretPos := Point(0, 0);嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻
嘻嘻嘻真好玩嘻嘻嘻嘻
嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻
比如我的richedit能显示11行,光标在第12行