在下面的代码中可以实现Edit1.Text中输入6个字母或数字时Edit2.SetFocus,那么我想让Edit2.text中输入6个字母时实现Edit3获得焦点,有没有简单一点的方法,谢谢大家了!!!procedure TForm2.Edit1Change(Sender: TObject);
var
str:string;
i:integer;
begin
str:='';
str:=Edit1.Text;
if (Length(str)>0) then
if (not((str[Length(str)])in['0'..'9','A'..'Z',#8]))or(Length(str)>6) then
begin
Edit1.Text:=LeftStr(Str,Length(str)-1);
end;
Edit1.SelStart:=Length(Edit1.Text);
if Length(str)>=6 then
Edit2.SetFocus;
end;
var
str:string;
i:integer;
begin
str:='';
str:=Edit1.Text;
if (Length(str)>0) then
if (not((str[Length(str)])in['0'..'9','A'..'Z',#8]))or(Length(str)>6) then
begin
Edit1.Text:=LeftStr(Str,Length(str)-1);
end;
Edit1.SelStart:=Length(Edit1.Text);
if Length(str)>=6 then
Edit2.SetFocus;
end;
解决方案 »
- ---- 给定几个值,如何用一个函数返回最小值??
- 如何用delphi来写分割图片库文件,如传奇的wis库文件中的图片
- ■■■ 关于写 ini文件里奇怪的问题????
- delphi编的程序能在unix下用吗?
- MSMQ
- intraweb中Service Application类型的工程中使用ClientDataSet时,数据显示不出来,怎么办?
- 求Delphi怎样快速搜索游戏的内存啊?
- 急!!WindowsXP可以上网,却用不了网上邻居!在线等!!!!!!!
- 出错?
- 请问如何实现当进入一个combox时自动下拉列表框(不用用鼠标去点)
- 实现一个按月份统计的表
- 利用GDI+,将png图像转换为jpg图像时,如何设置png的透明背景色转换为jpg的白色背景色
这样他的change事件就绑定到Edit1的了
然后代码里
str:=Edit1.Text ;改成
str := TEdit(sender).Text;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
beginif not( key in ['0'..'9','A'..'Z',#8]) then
key:=#0;
if Length(Edit1.Text)>=5 then
Edit2.SetFocus;
end;
那怎么把下面的Edit获得SetFoucs
编号的方法中用tedit的tag属性,然后仍用你的判断程序:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,strutils;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure EditChange(Sender: TObject);
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.EditChange(Sender: TObject);
var
i:integer;
currbutton,nextbutton:tedit;
str:string;
begin
currbutton := tedit( sender);
str:='';
str:=currbutton.Text;
if (Length(str)>0) then
if (not((str[Length(str)])in['0'..'9','A'..'Z',#8]))or(Length(str)>6) then
begin
currbutton.Text:=LeftStr(Str,Length(str)-1);
end;
currbutton.SelStart:=Length(currbutton.Text);
if Length(str)>=6 then
begin
if currbutton.tag=6 then
nextbutton:=edit1
else
for i:=0 to ComponentCount-1 do
begin
if Components[i].Tag=currbutton.tag+1 then
begin
nextbutton:=tedit( Components[i]);
break;
end;
end;
nextbutton.SetFocus;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
for i:=0 to ComponentCount-1 do
begin
if Components[i].Tag<>0 then
(Components[i] as Tedit).OnChange:=EditChange;
end;
end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, StrUtils;type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
sTmpName: string;
begin
sTmpName := TEdit(Sender).Name;
if not( key in ['0'..'9','A'..'Z',#8]) then
key:=#0;
if Length(TEdit(sender).Text) >= 5 then
(FindComponent('Edit'
+ IntToStr( StrToInt(RightStr(sTmpName, Length(sTmpName) - 4)) + 1 ))
as TEdit
).SetFocus;
end;procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
var
sTmpName: string;
begin
sTmpName := TEdit(Sender).Name;
if not( key in ['0'..'9','A'..'Z',#8]) then
key:=#0;
if Length(TEdit(sender).Text) >= 5 then
(FindComponent('Edit'
+ IntToStr( StrToInt(RightStr(sTmpName, Length(sTmpName) - 4)) + 1 ))
as TEdit
).SetFocus;
end;end.