还必须将 form 的 KeyPreview 属性更改为 true 例: procedure TfrmMain.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);begin edit1.Text:=inttostr(key); if (ssCtrl in Shift) and (key=85) then begin
end; end;
昨天刚刚看到的方法: SetWindowLong(Edit1.Handle, GWL_STYLE, GetWindowLong(Edit1.Handle, GWL_STYLE) or ES_NUMBER); 详细请看: http://expert.csdn.net/Expert/topic/1830/1830978.xml?temp=.5564539
procedure TForm1.Edit1KeyPress(Sender:TObject;var Key:Char); begin if not(key in ['0'..'9'])and not(key in['A'..'Z'] begin key:=chr[0];//将输入的字符置为空,相当于没有输入 showmessage('输入错误,请输入数字或大写字符'); end; end;
例:
procedure TfrmMain.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);begin
edit1.Text:=inttostr(key);
if (ssCtrl in Shift) and (key=85) then
begin
end;
end;
SetWindowLong(Edit1.Handle, GWL_STYLE,
GetWindowLong(Edit1.Handle, GWL_STYLE) or
ES_NUMBER); 详细请看:
http://expert.csdn.net/Expert/topic/1830/1830978.xml?temp=.5564539
begin
if not(key in ['0'..'9'])and not(key in['A'..'Z']
begin
key:=chr[0];//将输入的字符置为空,相当于没有输入
showmessage('输入错误,请输入数字或大写字符');
end;
end;
SetWindowLong(Edit1.Handle, GWL_STYLE,
GetWindowLong(Edit1.Handle, GWL_STYLE) or
ES_NUMBER);