关于Edit输入的简单问题(20分)

I

iranjn

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样在程序中使用户只能输入阿拉伯数字?
 
可以用MASKEDIT啊
 
在FormCreate中加一句:
SetWindowLong(Edit1.Handle,
GWL_STYLE,GetWindowLong(Edit1.Handle, GWL_STYLE) or ES_NUMBER);
 
keypress事件里
if not (key in ['0'..'9']) then
key:=#0;
 
参考
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1410308
 
在ONKEYPRESS事件中加入
if key not in ('0'..'9') then exit;
 
来晚了.只有说同意的份
在ONKEYPRESS中
if not (key in ['0'..'9']) then
key := #0;
 
try
key in ['0'..'9'];
except
key := #0;
end;
 
我也来晚了,同意lcl_003的方法,我就是用这个方法,不过还要补充一点,程序如下:
在Edit的Onkeypress事件里
if not (Key in ['0'..'9', #13, #8]) then
Key := #0;
要不然按删除键和回车键都会无效。
 

if not (Key in ['0'..'9', #13, #8]) then
Key := #0;
 
在FormCreate中加一句:
SetWindowLong(Edit1.Handle,
GWL_STYLE,GetWindowLong(Edit1.Handle, GWL_STYLE) or ES_NUMBER);
这才是真正的上策!!!
 
在 keypress事件里
if not (key in ['0'..'9']) then
key:=#0;
 
顶部