自己写的 限制文本框TEdit中只能输入数字
Posted 不能富贵难成大器皆因懒, 胸无大志庸庸碌碌只为闲。
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自己写的 限制文本框TEdit中只能输入数字相关的知识,希望对你有一定的参考价值。
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;
以上是关于自己写的 限制文本框TEdit中只能输入数字的主要内容,如果未能解决你的问题,请参考以下文章