W
wjqdelphi
Unregistered / Unconfirmed
GUEST, unregistred user!
我自己作的一共Edit控件:
unit DimEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls,Forms,Dialogs,Graphics;
Type
TDimStyle=(horizontal,vertical);
type
TDimEdit = class(TEdit)
private
FCanInPut: boolean;
procedure SetCanInPut(const Value: boolean);
{ Private declarations }
protected
procedure Click; override;
procedure keypress(var Key: Char);override;
procedure KeyDown(var Key: Word; Shift: TShiftState);override;
procedure DoExit;override;
{ Protected declarations }
public
{ Public declarations }
constructor NewCreate(Aowner: TComponent);
published
property CanInPut:boolean read FCanInPut write SetCanInPut;
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('DimEdit', [TDimEdit]);
end;
{ TDimEdit }
constructor TDimEdit.NewCreate(Aowner: TComponent);
begin
inherited create(Aowner);
CanInPut:= False;
BorderStyle:= bsnone ;
Color:= clwhite;
Width:= 30;
Height:= 15;
BorderWidth:=0;
end;
procedure TDimEdit.SetCanInPut(const Value: boolean);
begin
FCanInPut := Value;
end;
procedure TDimEdit.Click;
begin
inherited;
CanInPut:= True;
SelectAll;
Height:= 18;
sendmessage(getfocus, WM_SETFOCUS, 0, 0);
end;
procedure TDimEdit.keypress(var Key: Char);
begin
inherited;
if Not( CanInPut and (key in ['0'..'9',#8])) then
begin
key := #0;
exit;
end;
end;
procedure TDimEdit.KeyDown(var Key: Word; Shift: TShiftState);
begin
inherited;
if Key= 13 then
begin
BorderStyle:= bsNone;
CanInPut:= False;
Height:= 15;
sendmessage(getfocus, WM_KILLFOCUS, 0, 0);
end;
end;
procedure TDimEdit.DoExit;
begin
inherited;
BorderStyle:= bsNone;
CanInPut:= False;
Height:= 18;
end;
procedure TDimEdit.DimExit(Sender: TObject);
begin
BorderStyle:= bsNone;
CanInPut:= False;
Height:= 18;
end;
动态创建时,点击它时总会不断触发onexit,哪的问题?
unit DimEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls,Forms,Dialogs,Graphics;
Type
TDimStyle=(horizontal,vertical);
type
TDimEdit = class(TEdit)
private
FCanInPut: boolean;
procedure SetCanInPut(const Value: boolean);
{ Private declarations }
protected
procedure Click; override;
procedure keypress(var Key: Char);override;
procedure KeyDown(var Key: Word; Shift: TShiftState);override;
procedure DoExit;override;
{ Protected declarations }
public
{ Public declarations }
constructor NewCreate(Aowner: TComponent);
published
property CanInPut:boolean read FCanInPut write SetCanInPut;
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('DimEdit', [TDimEdit]);
end;
{ TDimEdit }
constructor TDimEdit.NewCreate(Aowner: TComponent);
begin
inherited create(Aowner);
CanInPut:= False;
BorderStyle:= bsnone ;
Color:= clwhite;
Width:= 30;
Height:= 15;
BorderWidth:=0;
end;
procedure TDimEdit.SetCanInPut(const Value: boolean);
begin
FCanInPut := Value;
end;
procedure TDimEdit.Click;
begin
inherited;
CanInPut:= True;
SelectAll;
Height:= 18;
sendmessage(getfocus, WM_SETFOCUS, 0, 0);
end;
procedure TDimEdit.keypress(var Key: Char);
begin
inherited;
if Not( CanInPut and (key in ['0'..'9',#8])) then
begin
key := #0;
exit;
end;
end;
procedure TDimEdit.KeyDown(var Key: Word; Shift: TShiftState);
begin
inherited;
if Key= 13 then
begin
BorderStyle:= bsNone;
CanInPut:= False;
Height:= 15;
sendmessage(getfocus, WM_KILLFOCUS, 0, 0);
end;
end;
procedure TDimEdit.DoExit;
begin
inherited;
BorderStyle:= bsNone;
CanInPut:= False;
Height:= 18;
end;
procedure TDimEdit.DimExit(Sender: TObject);
begin
BorderStyle:= bsNone;
CanInPut:= False;
Height:= 18;
end;
动态创建时,点击它时总会不断触发onexit,哪的问题?