文本框只能输入数字
2009-12-10 22:01
274 查看
procedure TMainForm.edtListViewIndexKeyPress(Sender: TObject;
var Key: Char);
begin
if not (Key in ['0'..'9', #8]) then
Key := #0;
end;
在ONKEYPRESS里写下
procedure Tform1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key>'9' or key<'0' then abort
end;
procedure TSellForm.NumEditKeyPress(Sender: TObject; var Key: Char);
begin
if key in ['0'..'9'] then
else
Key:=#0;
end;
procedure TQueryBilForm.ComPTextKeyPress(Sender: TObject; var Key: Char);
begin
if Assigned(CurField) then
begin
if (CurField.DataType in [ftFloat,ftCurrency,ftBCD]) then
begin
if not((key in ['0'..'9','.','-',#8])) then
begin
key := #0
end
else
begin
if (Key='.') and (Pos('.',TEdit(Sender).Text)<>0) then
Key:=#0
else if
(Key='-') and (Pos('-',TEdit(Sender).Text)<>0) then
Key:=#0;
end;
end
else if (CurField.DataType in [ftAutoInc,ftSmallint, ftInteger, ftWord,
ftBytes,ftLargeint]) then
begin
if not ((Key in ['0'..'9','-',#8])) then
begin
Key:=#0
end
else
begin
if(Key='-') and (Pos('-',TEdit(Sender).Text)<>0) then
Key:=#0;
end;
end
else
Exit;
end;
end;
try
StrtoFloat(Edit1.Text);
except
messagebox(handle,'请输入数字!',mb_ok);
end;
Edit 中只输入数字
SetWindowLong(Edit1.Handle, GWL_STYLE,
GetWindowLong(Edit1.Handle, GWL_STYLE) or
ES_NUMBER);
在edit1 keypress事件中加入以下代码即可:
procedure TForm1.edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9','.',#13,#8]) then key:=#0;
if (key = '.') and (Pos('.', edit1.text) > 0) then key:= #0;
end;
if Not(Key in ['0'..'9'])
再加两个,
if Not(Key in ['0'..'9',#8,#13])
不然按删除或者都会出提示
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if Not(Key in ['0'..'9',#8,#13]) then
begin
key:=#0; //把输入的字符清空
ShowMessage('输入不是数字');
end;
end;
Var
I : Integer;
Begin
Try
I := StrToInt(Edit1.Text);
Except
ShowMessage('XXXX');
end;
[分享]限制文本框只能输入数字(delphi)
if not (key in ['.','0'..'9',#8,#13])then key:=#0; //只能输入数字、小数点和回车、退格
if (key in ['.'])and (pos('.',Edit1.Text)>0)then key:=#0; //只能输入一个小数点
if (key in ['.'])and(length(Edit1.Text)<1)then key:=#0; //第一位不能为小数点
if (key in ['0'])and (pos('.',Edit1.Text)<1)and(copy(Edit1.Text,1,1)='0') then
key:=#0;
//------------------------------------------------------------------------------------------
//只可输入数值
if key=#8 then
else if (key<#48) or (key>#57) then
begin
application.MessageBox('您输入的不是数值!','SUER个人工作室',mb_ok+mb_iconquestion);
key:=#0;
end
else
//------------------------------------------------------------------------------------------
var Key: Char);
begin
if not (Key in ['0'..'9', #8]) then
Key := #0;
end;
在ONKEYPRESS里写下
procedure Tform1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key>'9' or key<'0' then abort
end;
procedure TSellForm.NumEditKeyPress(Sender: TObject; var Key: Char);
begin
if key in ['0'..'9'] then
else
Key:=#0;
end;
procedure TQueryBilForm.ComPTextKeyPress(Sender: TObject; var Key: Char);
begin
if Assigned(CurField) then
begin
if (CurField.DataType in [ftFloat,ftCurrency,ftBCD]) then
begin
if not((key in ['0'..'9','.','-',#8])) then
begin
key := #0
end
else
begin
if (Key='.') and (Pos('.',TEdit(Sender).Text)<>0) then
Key:=#0
else if
(Key='-') and (Pos('-',TEdit(Sender).Text)<>0) then
Key:=#0;
end;
end
else if (CurField.DataType in [ftAutoInc,ftSmallint, ftInteger, ftWord,
ftBytes,ftLargeint]) then
begin
if not ((Key in ['0'..'9','-',#8])) then
begin
Key:=#0
end
else
begin
if(Key='-') and (Pos('-',TEdit(Sender).Text)<>0) then
Key:=#0;
end;
end
else
Exit;
end;
end;
try
StrtoFloat(Edit1.Text);
except
messagebox(handle,'请输入数字!',mb_ok);
end;
Edit 中只输入数字
SetWindowLong(Edit1.Handle, GWL_STYLE,
GetWindowLong(Edit1.Handle, GWL_STYLE) or
ES_NUMBER);
在edit1 keypress事件中加入以下代码即可:
procedure TForm1.edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9','.',#13,#8]) then key:=#0;
if (key = '.') and (Pos('.', edit1.text) > 0) then key:= #0;
end;
if Not(Key in ['0'..'9'])
再加两个,
if Not(Key in ['0'..'9',#8,#13])
不然按删除或者都会出提示
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if Not(Key in ['0'..'9',#8,#13]) then
begin
key:=#0; //把输入的字符清空
ShowMessage('输入不是数字');
end;
end;
Var
I : Integer;
Begin
Try
I := StrToInt(Edit1.Text);
Except
ShowMessage('XXXX');
end;
[分享]限制文本框只能输入数字(delphi)
if not (key in ['.','0'..'9',#8,#13])then key:=#0; //只能输入数字、小数点和回车、退格
if (key in ['.'])and (pos('.',Edit1.Text)>0)then key:=#0; //只能输入一个小数点
if (key in ['.'])and(length(Edit1.Text)<1)then key:=#0; //第一位不能为小数点
if (key in ['0'])and (pos('.',Edit1.Text)<1)and(copy(Edit1.Text,1,1)='0') then
key:=#0;
//------------------------------------------------------------------------------------------
//只可输入数值
if key=#8 then
else if (key<#48) or (key>#57) then
begin
application.MessageBox('您输入的不是数值!','SUER个人工作室',mb_ok+mb_iconquestion);
key:=#0;
end
else
//------------------------------------------------------------------------------------------
相关文章推荐
- GUI_如何控制在文本框里面只能输入数字字符案例
- .net(c#) winform文本框只能输入数字,不能其他非法字符
- 文本框只能输入数字和小数点,且小数点后只允许两位数字
- 正则表达式限制文本框只能输入中文或者英文或者数字
- 文本框只能输入数字(兼容IE火狐)
- 限制文本框只能输入数字||只能是数字和小数点||只能是整数和浮点数
- 用Jquery控制文本框只能输入数字和字母
- 用正则表达式限制文本框只能输入数字,小数点,英文字母,汉字等各类代码
- 用正则表达式限制文本框只能输入数字,小数点,英文字母,汉字等各类代码
- 在网页里让文本框只能输入数字的一种方法。外加回车换Tab
- 验证文本框只能输入数字
- Jquery限制文本框只能输入数字(小数点也可以)
- JS限制文本框只能输入数字和字母方法
- 正则表达式限制文本框只能输入数字
- silverlight 文本框只能输入数字
- 文本框只能输入数字
- js控制文本框只能输入中文、英文、数字与指定特殊符号的实现代码
- [小技巧]文本框中限制只能输入数字,也不允许Ctrl+V
- 文本框只能输入数字和退格键
- 用javascript限制一个文本框只能输入数字