使用这种功能必须使用 OnKeyPress 事件,该事件是在窗体中获得键盘输入的焦点,并且在用户按键时发生.OnKeyPress 事件中有个重要参数:Key.Key 参数为Char 型,它能够获得用户的按键值.下面的代码就只能输入0~9 之间的数字,且只能输入一个小数点,按下其他键时无效. procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin ]) then key:=#; ) then key:=#; end
procedure TForm4.Edit1KeyPress(Sender: TObject; var Key: Char); begin , #]) then begin Key := #; end else begin if Key = '-' then begin if not string(TEdit(Sender).Text).Contains('-') then begin //光标定位在第一个上 TEdit(Sender).SelStart := ; end else begin
如果按照下面方式,则无论你输入什么,都会打印12,因为raw_input接受的输入是按照字符串处理的 num = raw_input('please enter a num:') if num > 10: print 12 else: print -abs(int(num)) 需要改成下面的写法就OK了: num = raw_input('please enter a num:') if int(num) > 10: print 12 else: print -abs(int(num))