MEMO控件字符窜控制

test88666 2015-02-05 11:26:53
想要在MEMO里面实现回车键自动换行,并且空两格。
在线等,请大家不吝赐教!
...全文
257 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
test88666 2015-02-10
  • 打赏
  • 举报
回复
多谢大家帮助,总算找到了正确方法了!
test88666 2015-02-07
  • 打赏
  • 举报
回复
引用 6 楼 lyhoo163 的回复:
var MyList:TStringList;
  S:string;
begin
  MyList:=TStringList.Create;
  MyList.Text:=Memo1.Text;
  for i:=MyList.Count-1 downto 0 do
  begin
    S:=Trim(MyList.Strings[i]);
    MyList.Strings[i]:='    '+S;
  end;
  Memo1.Text:=MyList.Text;
  MyList.Free;
end;
不行啊,位置老是往上面跑的。
胡伟峰 2015-02-07
  • 打赏
  • 举报
回复

procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    Memo1.Lines.Append('  ');    //空两个
    Key := #0;    //忽略原来的回车换行
    Memo1.SelStart := Length(Memo1.Text) - 1;    //重新定位
  end;
end;
lyhoo163 2015-02-06
  • 打赏
  • 举报
回复
var MyList:TStringList;
  S:string;
begin
  MyList:=TStringList.Create;
  MyList.Text:=Memo1.Text;
  for i:=MyList.Count-1 downto 0 do
  begin
    S:=Trim(MyList.Strings[i]);
    MyList.Strings[i]:='    '+S;
  end;
  Memo1.Text:=MyList.Text;
  MyList.Free;
end;
lyhoo163 2015-02-06
  • 打赏
  • 举报
回复
建议使用TRichEdit;
test88666 2015-02-06
  • 打赏
  • 举报
回复
引用 3 楼 doloopcn 的回复:
MEMO中很头痛的事情就是不知道光标所在的行和列,所以做分页必须知道光标的位置: var xRow,yCol,Num,CharsLine:longint; begin Num:=SendMessage(Memo1.Handle,EM_LINEFROMCHAR,Memo1.SelStart,0); CharsLine:=SendMessage(Memo1.Handle,EM_LINEINDEX,Num,0); xRow:=Num+1;//当前行 yCol:=(Memo1.SelStart-CharsLine)+1;//当前列 用SendMessage这个函数可以得知MEMO的行列,希望对你有帮助 http://bbs.csdn.net/topics/390952070 这是我上一个贴子贴出来的 在KeyPress后(我觉得不应该是在KeyDown或KeyUp后),调用一次函数,然后Memo1.Lines[xRow]:=' '+Memo1.Lines[xRow]; 就能实现楼主的效果了
还是无法实现。
doloopcn 2015-02-06
  • 打赏
  • 举报
回复
MEMO中很头痛的事情就是不知道光标所在的行和列,所以做分页必须知道光标的位置: var xRow,yCol,Num,CharsLine:longint; begin Num:=SendMessage(Memo1.Handle,EM_LINEFROMCHAR,Memo1.SelStart,0); CharsLine:=SendMessage(Memo1.Handle,EM_LINEINDEX,Num,0); xRow:=Num+1;//当前行 yCol:=(Memo1.SelStart-CharsLine)+1;//当前列 用SendMessage这个函数可以得知MEMO的行列,希望对你有帮助 http://bbs.csdn.net/topics/390952070 这是我上一个贴子贴出来的 在KeyPress后(我觉得不应该是在KeyDown或KeyUp后),调用一次函数,然后Memo1.Lines[xRow]:=' '+Memo1.Lines[xRow]; 就能实现楼主的效果了
test88666 2015-02-05
  • 打赏
  • 举报
回复
引用 1 楼 gaohx6851 的回复:
procedure TForm1.mmo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = 13 then mmo1.Lines.Add(#13#10); end;
第一次换行距离超大,而且也无法缩进两个字。
gaohx6851 2015-02-05
  • 打赏
  • 举报
回复
procedure TForm1.mmo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = 13 then mmo1.Lines.Add(#13#10); end;

5,388

社区成员

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

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