在Combobox的KeyPress事件中判断: if not key in ['0..9',#45] then key=#0 具体也不太记得了,反正是这么控制的
if not key in ['0'..'9',#8,#13] then Key :=#0
我在keypress事件里写了此代码,可以控制,但是不能控制输入汉字 If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0 MsgBox "输入数字。", vbInformation, "提示" End If
上面回答的也差不多了吧,还要防止用Ctrl+V向里粘。
procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char); begin if not (key in ['0'..'9'] )then begin showmessage('·Ç·¨×Ö·û'); key:=#0; end; end;
if not key in ['0..9',#45] then key=#0
具体也不太记得了,反正是这么控制的
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
MsgBox "输入数字。", vbInformation, "提示"
End If
procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9'] )then
begin
showmessage('·Ç·¨×Ö·û');
key:=#0;
end;
end;