edit中只能输入数字、小数点等等候,还能使用ctrl+c和ctrl+c的办法

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  case Key of
     '0'..'9':   ;      //对数字键响应
     #8,#9,#37,#39,#46,#35,#36:;  //对退格键、Tab键、左右箭头响应
     #1,#3,#22,#24:;//对Ctrl C、V、A、X响应

原帖http://www.delphibbs.com/delphibbs/dispq.asp?lid=1410308

对自己程序的修改:

  if not(key in ['0'..'9', #8, #13,#45, #27, '.',#3,#22,#24]) then
    key:=#0;
  if (key='.') and (Pos('.',TEdit(Sender).Text)>0) then
  key:=#0;

posted @ 2011-04-01 23:03  吴越  阅读(218)  评论(0编辑  收藏  举报