richedit光标定位和回车问题
时间:2011-09-22
来源:互联网
A=C×B
A= //按下回车时“A=”自动生成,且光标定位在“=”号右边该如何做。现在实现了“A=”自动生成功能,但是每次回车均产生2行,而不是一行。本人前面发帖请教过,但效果不理想,在一次发帖请高手帮忙。3Q!代码如下:
Delphi(Pascal) code
unit ata01; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, ComCtrls, Grids, DBGrids; type TForm1 = class(TForm) GroupBox1: TGroupBox; Edit1: TEdit; Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; RichEdit1: TRichEdit; procedure FormCreate(Sender: TObject); procedure RichEdit1KeyPress(Sender: TObject; var Key: Char); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin richedit1.Text:=''; end; procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char); var i,k :integer; s,ls:string; begin if richedit1.Lines.Count>0 then i:=richedit1.Lines.Count-1 else i:=0; if key=#13 then begin s:=richedit1.Lines.Strings[i]; k:=pos('=',s); ls:=copy(s,1,k); richedit1.Lines.Add(ls); edit1.Text:=inttostr(richedit1.Lines.count); end; richedit1.SelStart:=k; richedit1.SetFocus; end; end.
作者: lcop2011 发布时间: 2011-09-22
作者: gzzai 发布时间: 2011-09-23
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls; type TForm1 = class(TForm) RichEdit1: TRichEdit; Edit1: TEdit; procedure RichEdit1KeyPress(Sender: TObject; var Key: Char); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin richedit1.Text:=''; end; procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char); var i,k :integer; s,ls:string; begin if key=#13 then begin key:=#0; if richedit1.Lines.Count<1 then exit; if richedit1.Lines.Count>0 then i:=richedit1.Lines.Count-1; s:=richedit1.Lines.Strings[i]; k:=pos('=',s); ls:=copy(s,1,k); richedit1.Lines.Add(ls); edit1.Text:=inttostr(richedit1.Lines.Count); richedit1.SelStart:=length(richedit1.Text); richedit1.SelLength:=0; richedit1.SetFocus; end; end; end.
作者: gzzai 发布时间: 2011-09-23
if Key = #13 then Key := #0;
作者: bdmh 发布时间: 2011-09-23
作者: lcop2011 发布时间: 2011-09-23
Delphi(Pascal) code
procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char); var i,k :integer; s,ls:string; begin if key=#13 then begin key:=#0; if richedit1.Lines.Count<1 then exit; i:=richedit1.Lines.Count-1; s:=richedit1.Lines.Strings[i]; k:=pos('=',s); ls:=copy(s,1,k); richedit1.Lines.Add(ls); edit1.Text:=inttostr(richedit1.Lines.Count); richedit1.SelStart:=length(richedit1.Text); richedit1.SelLength:=0; richedit1.SetFocus; end; end;
作者: gzzai 发布时间: 2011-09-23
Delphi(Pascal) code
procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char); var i,k :integer; s,ls:string; begin if key=#13 then//如果回车键被按下了 begin key:=#0;//把回车的动作消掉 if richedit1.Lines.Count<1 then exit;//如果richedit1没内容,不往下执行 i:=richedit1.Lines.Count-1;//取最后一行的索引值 s:=richedit1.Lines.Strings[i];//取最后一行的字符 k:=pos('=',s);//求等号在字符串的位置 ls:=copy(s,1,k);//从字符串第一个开始、复制到(包括)等号 richedit1.Lines.Add(ls);//将刚复制的字符串添加进richedit1内 edit1.Text:=inttostr(richedit1.Lines.Count);//在edit1中显示richedit1的行数 richedit1.SelStart:=length(richedit1.Text);//选择的起始位 richedit1.SelLength:=0;//选择字符的个数 richedit1.SetFocus;//让richedit1获得焦点 end; end;
作者: gzzai 发布时间: 2011-09-23
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28