procedure EditContentRestriction(AEditControl: TCustomEdit; Len: Integer; IsNumeric: Boolean; var Key: Char); procedure DoErr; begin Key := #0; MessageBeep(1); end; begin if Key = #8 then Exit; if Len > 0 then begin if AEditControl.SelLength > 0 then Exit; if Length(AEditControl.Text) > Len-1 then begin DoErr; Exit; end; end; if IsNumeric then if not (Key in ['0'..'9', #8]) then begin DoErr; Exit; end; end;_____________________ http://lysoft.7u7.net
在KeyPress事件中使用procedure TFrmPhoneBook.Edit2KeyPress(Sender: TObject; var Key: Char); begin EditContentRestriction(Sender as TCustomEdit, 20, True, Key); end;_____________________ http://lysoft.7u7.net
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if not (key in ['0'..'9',#8]) then key := #0; end;
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char); begin if not (Key in ['0'..'9', '.', #8, #46]) then Key := #0; end;
SetWindowLong(Edit1.Handle, GWL_STYLE,GetWindowLong(Edit1.Handle, GWL_STYLE) or ES_NUMBER);
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if not (key in ['0'..'9',#8]) then key := #0; end;
IsNumeric: Boolean; var Key: Char);
procedure DoErr;
begin
Key := #0;
MessageBeep(1);
end;
begin
if Key = #8 then Exit;
if Len > 0 then
begin
if AEditControl.SelLength > 0 then Exit;
if Length(AEditControl.Text) > Len-1 then
begin
DoErr;
Exit;
end;
end;
if IsNumeric then if not (Key in ['0'..'9', #8]) then
begin
DoErr;
Exit;
end;
end;_____________________
http://lysoft.7u7.net
begin
EditContentRestriction(Sender as TCustomEdit, 20, True, Key);
end;_____________________
http://lysoft.7u7.net
begin
if not (key in ['0'..'9',#8]) then
key := #0;
end;
begin
if not (Key in ['0'..'9', '.', #8, #46]) then
Key := #0;
end;
or ES_NUMBER);
begin
if not (key in ['0'..'9',#8]) then
key := #0;
end;