procedure Tfrm_jz.Edit1KeyPress(Sender: TObject; var Key: Char); begin if (key in ['0'..'9',#8,#13]) then begin if key=#13 then begin if length(edit1.Text)>2 then edit1.Text:=copy(edit1.Text ,1,(length(edit1.Text)-2))+'.'+copy(edit1.Text ,(length(edit1.Text)-1),2) ; if length(edit1.Text)=2 then edit1.Text:='0.'+edit1.Text; if length(edit1.Text)=1 then edit1.Text:='0.0'+edit1.Text; edit2.SetFocus; end end else key:=#0; end;
delphi edit 固定小数位数的实现方法的改进 ------------------------ procedure Tfrm_jz.Edit1KeyPress(Sender: TObject; var Key: Char); begin if (key in ['0'..'9',#46,#13]) then begin if (SubStrConut(Edit1.Text,'.')=1) and (key in [#46]) then key:=#0; if key=#13 then begin if (pos(',',edit1.text)=0) and (edit1.text<>'') then edit1.Text:=formatfloat('#,##0.00',strtofloat(edit1.Text)); edit2.SetFocus; end; end else if key in [#8] then edit1.text:='' else key:=#0; end;
delphi edit 固定小数位数的实现方法的改进(解决无法输入负数的问题) ------------------------
procedure Tfrm_jz.Edit1KeyPress(Sender: TObject; var Key: Char); begin if (key in ['0'..'9',#45,#46,#13]) then begin if (SubStrConut(Edit1.Text,'.')=1) and (key in [#46]) then key:=#0; if (SubStrConut(Edit1.Text,'-')=1) and (key in [#45]) then key:=#0; if key=#13 then begin if (pos(',',edit1.text)=0) and (edit1.text<>'') then if (pos('-',edit1.text)=0) or (pos('-',edit1.text)=1) then begin edit1.Text:=formatfloat('#,##0.00',strtofloat(edit1.Text)); edit2.SetFocus; end; end; end else if key in [#8] then edit1.text:='' else key:=#0; end;
|
请发表评论