找回密码
 立即注册
查看: 1371|回复: 0

delphi中控制一个edit中只能输入数字(包括小数点)

[复制链接]

6782

主题

8

回帖

2万

积分

管理员

积分
21777
发表于 2019-5-20 21:47:51 | 显示全部楼层 |阅读模式
procedure Tform1.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', #8, #13]) then
   key := char(0); //key:=char(' ');//#8是回退键,#13是回车键
if key = #13 then
begin
   selectnext(activecontrol, true, true);//跳转到下一个控件
end;
end;

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

edit  keypress

if Not (Key in ['0'..'9','.',#13,Char(vk_delete),Char(vk_back)]) then
   Key:=#0;
if (Key='.') and (Pos('.',Edit.Text)>0) then key:=#0;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表