关于memo定位的问题!~

EUII 2003-08-21 05:57:11
请问如何在memo的指定行的指定位置写入一个字符,假设行数和那行的位置可达!~
比如 想在第三行第两个字符的位置写入一个A
...全文
109 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
guothreelove2003 2003-08-22
  • 打赏
  • 举报
回复
取Tmemo的当前行及跳转到指定行
向Tmemo发送WM_KEYDOWN消息可实现跳转到指定行

var i,line,lineDest:integer;
//line表示取出的Memo1的当前行号
//lineDest表示需要跳到的行号

memo1.SetFocus;
line:=1;
lineDest:=2;

//取当前行号line
for i:=0 to length(memo1.text) do
begin
if memo1.Text[i]=chr(13) then line:=line+1;
if memo1.SelStart<=i then break;
end;

//跳转到LineDest行
if lineDest>line then
begin
for i:=line to lineDest-1 do
postmessage(memo1.handle,WM_KEYDOWN,VK_DOWN,0);
end
else if lineDest<line then
begin
for i:=lineDest to line-1 do
postmessage(memo1.handle,WM_KEYDOWN,VK_UP,0);
end;
EUII 2003-08-22
  • 打赏
  • 举报
回复
OK 研究一番先!~ 回来结帐 :)
lxpbuaa 2003-08-22
  • 打赏
  • 举报
回复
var
S: String;
begin
with Memo1 do
begin
S := Lines[1];
Insert('A', S, 3);
Lines[1] := S;
end;
end;

————————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
————————————————————————————————————
EUII 2003-08-22
  • 打赏
  • 举报
回复
那好!~ 我试试 调通给分!~
DWGZ 2003-08-22
  • 打赏
  • 举报
回复
都一样所有的Hanle, 改成Memo1.Handle
EUII 2003-08-22
  • 打赏
  • 举报
回复
怎么没有人回贴了!~~~ 晕 ,我自己顶一下
EUII 2003-08-21
  • 打赏
  • 举报
回复
sixgj(轰炸机)能不能说详细一点 :)
DWGZ() 你是在richedit里的啊!~ 你这两个过程是不是自定义的? 我没有看太明白 能不能解释一下 谢谢
DWGZ 2003-08-21
  • 打赏
  • 举报
回复
顶行设定:
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));




sixgj 2003-08-21
  • 打赏
  • 举报
回复
呵呵。那就用到stringlist好了。

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧