我想在Edit中输入数字,其他的东西一概抛弃,请问有什么办法可以做到。请高手告赐教最简单的办法。谢谢。

解决方案 »

  1.   

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

  2.   

    第1方法:改用maskedit控件。
    另外就是:在edit的onkeypress加入限制判断。代码不写了.
      

  3.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if not (Key in ['0'..'9','.']) then Key := #0;
    end;
    还得要能输入小数据点啊:)
      

  4.   

    还有方法:
      SetWindowLong( Edit1.Handle, GWL_STYLE, GetWindowLong(Edit1.Handle, GWL_STYLE) Or ES_NUMBER );
      

  5.   

    if not (Key in ['0'..'9','.',#8]) then Key := #0;
    再加一個#8吧!
      

  6.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if not (Key in ['0'..'9','.',#8]) then Key := #0;
    end;
    还得要能输入退格鍵啊  :)