怎么使Edit里面只能输入数字 找免费财务软件
2楼: 1, 新作个控件,从Tedit继承.
2,在edit得keypress事件中 控制,
if not Byte(key) in (39..47) then
key := #0;
没测试, 记不清 0到9的asc码了. 如易语言进销存源码
3楼: 大哥,怎么编译通不过,提示大概是那两个点不通过
4楼: 编译过了还是不行,能够输入任意字符
5楼: procedure TForm1.edt1KeyPress(Sender: TObject; var Key: Char);
begin
if (Key<''0'') or (Key>''9'') then
Key := Char(0);
end;
6楼: 谢谢帮助
销售管理软件版7楼: 如果你的edit是数据敏感的,数据类型是数值型,则不用任何代码。如果不是数据敏感,可以采用楼上的代码,但还需要考虑DEL等键。
另外,许多第三方控件包里都有edit控件,可以设置输入格式是string还是num。
8楼: //输入
begin
if not (key in [''0''..''9'',#8,#46]) then
begin
key:=#0 ;
end;
//#8和#46分别代表
//只接
procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.Clear;
SetWindowLong(Edit1.Handle, GWL_STYLE,
GetWindowLong(Edit1.Handle, GWL_STYLE) or ES_NUMBER);
end;
9楼: procedure TMOFrm.EditKeyPress(Sender: TObject; var Key: Char);
begin
if not (key in [''0''..''9'',''.'',#8]) then key:=#0;
End;
10楼: if key in [''0''..''9'',''.'',#08] then
else
begin
ShowMessage(''请输入数字!'');
Key:=#0;
end;
11楼: 如果再限制其长度和回车焦点到下一个Edit里,又该怎么做啊?
谢谢各位回帖
12楼: 多人接受答案了。 如免费财务软件