在Edit的KeyPress事件中输入以下代码: procedure Form1.Edit1KeyPress(Sender: TObject; var Key: Char); var i:Integer; begin if not (Key in [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']) then Key := #0; end; end;
在Edit的KeyPress中加入:if not(Key in ['0'..'9',#13,#8,'.']) then Key:=#0;
在TEdit的key里写 if not(key in {'0'..'9','#8,#13]) then begin key:=#0; Application.MessageBox('您输入了非数字数据!','错误',mb_ok+mb_iconerror); end;
在Tedit的KeyPress事件中判断,如下: procedure TFORM1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if Key in ['0'..'9',#8,#13] = False then begin Application.MessageBox('只能输入数字! ','系统提示',MB_OK+MB_ICONWARNING); Edit1.SetFocus; Abort; end; end;
if not(key in {'0'..'9','#8,#13]) then 呵呵上面打错了~不好意思啊~ if not(key in ['0'..'9','#8,#13]) then
要绝对控制只有在变化事件里面写,判断如果不合法就恢复到变化前 要求不高的话在KeyPress里面写 if not (key in ['0'..'9',#8]) then key := #0
procedure Form1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
i:Integer;
begin
if not (Key in [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']) then
Key := #0;
end;
end;
Key:=#0;
if not(key in {'0'..'9','#8,#13]) then
begin
key:=#0;
Application.MessageBox('您输入了非数字数据!','错误',mb_ok+mb_iconerror);
end;
procedure TFORM1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if Key in ['0'..'9',#8,#13] = False then
begin
Application.MessageBox('只能输入数字! ','系统提示',MB_OK+MB_ICONWARNING);
Edit1.SetFocus;
Abort;
end;
end;
呵呵上面打错了~不好意思啊~
if not(key in ['0'..'9','#8,#13]) then
要求不高的话在KeyPress里面写
if not (key in ['0'..'9',#8]) then
key := #0