bbkxjy:
我试了不行,我的代码如下望帮助改一下谢谢。
unit Szedit1;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;
type
TSzedit = class(TEdit)
private
protected
procedure KeyPress(var Key: Char); override;
procedure Change; override;
Constructor Create(AOwner: TComponent); override;
public
published
end;
procedure Register;
implementation
Constructor TSZEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle - [csSetCaption];
Text := '0';
end;
procedure TSZEdit.Change;
var
Str : string;
begin
Str := FormatFloat('00.00', StrToFloat(Text));//转换,这里的格式只是举例
Perform(WM_SETTEXT, 0, LongInt(PChar(Str))); //发消息设置 Text 属性
inherited Change;
end;
procedure Register;
begin
RegisterComponents('Standard', [TSzedit]);
end;
procedure TSzedit.KeyPress(var Key: Char);
begin
if key=#8 then exit;
if not (key in['0'..'9']) then
begin
key:=#0;
MessageBeep(0);
end;
end;
end.