怎样让edit只能接收数字
编号:QA002881
建立日期: 2000年4月24日 最后修改日期:2003年6月22日
所属类别:
Q
LHQ:
操作系统: Win98
编程工具: Delphi 3.0 C/S
问题: 怎样让edit只能接收数字,其它字符一概输入不进去?
水平: 刚入门
A回答:
可以这样:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if (Key < '0') or (Key > '9') then
Key := Chr(0); // 如果不是数字则忽略
end;
小苏的意见:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
try
strtoint(key);
except
edit1.text:=copy(edit1.text,length(edit1.text)-1,1);
exit;
end;
end;
相关问题:
QA002111 "KEYPRESS,KEYDOWN,KEYUP三事件的区别"
此问题由李海回答。
| |
|
|
| |
|
|