如何编写一个控件的一些属性(100分)

  • 主题发起人 主题发起人 smj_9547
  • 开始时间 开始时间
S

smj_9547

Unregistered / Unconfirmed
GUEST, unregistred user!
我想编写一个控件,从TEDIT中继承过来。但是我要在进入这个控件的时候,
将EDIT.color改变.离开的时候将EDIT。COLOR恢复!
希望能给出源代码!
 
这两个过程必须在你的控件的构造和析构中进行.

procedure MyControl.Create()
begin
FEdit.Color:=111111;
Inherated();
end;


procedure MyControl.Destroy()
begin
Inherated();
FEdit.Color:=原值;
end;

 
unit MyDBEDIT;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Mask, DBCtrls;

type
TMyDBEDIT = class(TDBEDIT)
private
FFocusColor: TColor;
FColor:TColor;
procedure SetFocusColor(const Value: TColor);
procedure CurEnter(var msg:TCMENTER);message cm_enter;
procedure CurEnter(var msg:TCMleave);message cm_leave;
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
property FocusColor:TColor read FFocusColor write SetFocusColor;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [TMyDBEDIT]);
end;

{ TMyDBEDIT }

procedure TMyDBEDIT.CurEnter(var msg: TCMENTER);
begin
FColor:=Color;
Color:=FFocusColor;
end;

procedure TMyDBEDIT.CurEnter(var msg: TCMleave);
begin
Color:=FColor;
end;

procedure TMyDBEDIT.SetFocusColor(const Value: TColor);
begin
FFocusColor := Value;
end;

end.
 
对于DJDSZ的答案给我一定的提示,但是有一个消息是定义错了。
离开的消息是CM_EXIT而不是CM_LEAVE。
而EXPECT的答案好象不是很明白我的意思。可能是我的意思没有说明白!
 

unit Edit2;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TEdit2 = class(TEdit)
private
{ Private declarations }
FColor:TColor;
protected
{ Protected declarations }
procedure DoEnter; override;
procedure DoExit; override;
public
{ Public declarations }
published
{ Published declarations }
property Color:TColor read FColor write FColor;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [TEdit2]);
end;

{ TEdit2 }

procedure TEdit2.DoEnter;
begin
inherited;
FColor:=clRed;
end;

procedure TEdit2.DoExit;
begin
inherited;
FColor:=clBlue;
end;

end.
 
后退
顶部