怎样限制文本框只输入0~9以及小数点。

解决方案 »

  1.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
       if (not (key in['0'..'9'])) and  (key <> '.') then key := #0;
    end;
      

  2.   

    procedure TForm1.Edit1KeyPress(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;