procedure TForm4.Edit1KeyPress(Sender: TObject; var Key: Char); begin if not (Key in [‘0‘ .. ‘9‘, ‘.‘, ‘-‘, #8, #13]) then begin Key := #0; end else begin if Key = ‘-‘ then begin if not string(TEdit(Sender).Text).Contains(‘-‘) then begin //光标定位在第一个上 TEdit(Sender).SelStart := 0; end else begin Key := #0; end; end else if Key = ‘.‘ then begin if string(TEdit(Sender).Text).Contains(‘.‘) then begin Key := #0; end; end; end; end;
时间: 2024-10-12 03:43:53