以前见过一个的
// TExEdit
//对原有的LableEdit上加入了OnlyInputNumber选项来控制只可以输入数字
{==============================================================================}
{ TExEdit }
TKeyDown = procedure(sender: Tobject; Key: Word) of object;
TExEdit = class(TLabeledEdit)
private
FOnlyInputNumber: Boolean;
FKeyDown: TKeyDown;
FCaption: string;
procedure WMKeyDown(var Message: Tmessage); message WM_KeyUP;
procedure SetCaption(const Value: string);
protected
procedure SetOnlyInputNumber(Flag: Boolean);
public
// destructor Destroy; override;
constructor Create(AOwner: TComponent); override;
published
property OnlyInputNumber: Boolean read FOnlyInputNumber write SetOnlyInputNumber;
property OnKeyDown: TKeyDown read FkeyDown write FkeyDown;
property Caption: string read FCaption write SetCaption;
end;
procedure TExEdit.WMKeyDown(var Message: Tmessage);
var
vKey: string;
begin
if message.WParam = VK_Return then Fn.SendKey(0, VK_TAB, vkeyClick);
//---
vkey := copy(text, SelStart, 1); //得到输入的字符
if length(text) > 0 then
begin
// if (message.WParam in [$41..$5A,$61..$7A,vk_space,187..189,191,226])and FOnlyInputNumber then
// begin
(*再次过滤防止小键盘的按键被过滤*)
if (vkey[1] in ['a'..'z', 'A'..'Z', ' ', '=', ',', '+', '-', '*', '/', '/']) and FOnlyInputNumber then
begin
self.SelStart := self.SelStart - 1;
Fn.SendKey(self.Handle, VK_Delete);
dobleep(800, 100);
end;
// end;
end;
if assigned(FKeyDown) then self.OnKeyDown(self, message.WParam);
message.Result := 0;
// Fn.Free;
end;
procedure TExEdit.SetCaption(const Value: string);
begin
FCaption := Value;
self.EditLabel.Caption := FCaption;
end;
procedure TExEdit.SetOnlyInputNumber(Flag: Boolean);
begin
if Flag <> FOnlyInputNumber then FOnlyInputNumber := flag;
end;
constructor TExEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
LabelPosition := lpLeft;
end;