怎样让Edit控件只接受数字的输入?

jericho3164 2003-09-30 09:03:32
怎样让Edit控件只接受数字的输入?
...全文
77 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
cnhgj 2003-10-02
  • 打赏
  • 举报
回复
同意一楼
zdqyundou 2003-10-02
  • 打赏
  • 举报
回复
xuexi
sixgj 2003-10-02
  • 打赏
  • 举报
回复
呵呵。都说明白了啊。
我不懂电脑 2003-10-02
  • 打赏
  • 举报
回复
maskedit可以自己定义要输入地数据格式。]
hejianling305 2003-10-02
  • 打赏
  • 举报
回复
在edit的onkeypress事件中添加程序就行
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var p:integer; tp:TPoint;
begin
if key in ['0'..'9','+','-','.'] then
begin
if key in ['+','-'] then
begin
p:=pos('+',Edit1.Text)+pos('-',Edit1.Text);
if p>0 then key:=#0
else
begin
GetCaretPos(tp);
if tp.x>1 then key:=#0;
end;
end
else
if key='.' then
begin
p:=pos('.',Edit1.Text);
if p>0 then key:=#0;
end;
end
else if key>#31 then key:=#0;
end;
xjlqlqlq 2003-10-02
  • 打赏
  • 举报
回复
2。edit的keypress事件
过滤数字键,和功能键,
还要屏蔽掉默认的粘贴功能。
zhourongbiao 2003-10-02
  • 打赏
  • 举报
回复
用maskedit也不错,简单些。
大聪 2003-09-30
  • 打赏
  • 举报
回复
in['0'..'9', #8, #13, #27]) 还可以加一些,
CTRL,ATL,什么的,
你自己找找,键值
FrameSniper 2003-09-30
  • 打赏
  • 举报
回复
好方法!
hotdog911 2003-09-30
  • 打赏
  • 举报
回复
procedure TForm1.Edit1KeyPress(sender:TObject;var Key:char);
begin
if (key<'0') or (key>'9") then
key:=char(0);
end;
things 2003-09-30
  • 打赏
  • 举报
回复
1。SetWindowLong(Edit1.Handle, GWL_STYLE,
GetWindowLong(Edit1.Handle, GWL_STYLE) or
ES_NUMBER);

2。edit的keypress事件
if Not (Key in['0'..'9', #8, #13, #27]) then
begin
Key := #0;
Exit;
end;

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧