或者你控制输入框只能输入数字和小数点,而且最后最好在焦点离开前要判断输入的是否合法 在onKeyPress中 if not (Key in ['0'..'9', '.', #8]) then key := #0; 就可以限制输入了
MaskEdit好象不行,二楼说的那种不能控制输入类似00.001....
二楼的方法可以的 为了限制只能输一个小数点,需要再加一句话 procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if (not (Key in ['0'..'9', '.', #8])) or ((key='.') and (pos('.',edit1.Text)>0)) then key := #0; end;
在onKeyPress中
if not (Key in ['0'..'9', '.', #8]) then
key := #0;
就可以限制输入了
为了限制只能输一个小数点,需要再加一句话
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if (not (Key in ['0'..'9', '.', #8])) or ((key='.') and (pos('.',edit1.Text)>0)) then key := #0;
end;
要控制小数点就如hellolongbin所说的
如果你怕输入的有问题,可以在onExit里再另外在判断