W
whzww
Unregistered / Unconfirmed
GUEST, unregistred user!
我现在想设计一个扩展的 edit 控件,设置一个控制输入类型的属性InputType(Datetime,float,integer,string),当决定此editEx的允许输入类型以后,改动edit的color属性,可是我现在 在boject inspector内 可以通过改变InputType的设置改动Color属性,但是editEx的实际颜色 却没有变化,color属性的改变对它不起作用了,这是什么问题呢,那位高人帮忙看看
----------------测试源码-----------------------
unit IntEdit;
interface
uses
SysUtils, Classes, Controls, StdCtrls, Graphics, Messages;
type
TInType = (IsDatetime, IsFloat, IsInteger, IsString);
type
TStyleOption = (Flat, UseLabel);
type
TStyleOptions = set of TStyleOption;
type
TIntEdit = class(TEdit)
private
{ Private declarations }
FInputType: TInType;
FStyleOptions: TStyleOptions;
FAColor: string;
FColor: TColor;
FBrush:TBrush;
procedure SetAcolor(Value: string);
function GetAColor: string;
procedure setcolor(Value: TColor);
function GetColor: TColor;
procedure CMColorChanged(var Message: TMessage); message CM_ColorChanged;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property InputType: TInType read FInputType write FInputType;
property Options: TStyleOptions read FStyleOptions write FStyleOptions;
property InColor: string read GetAColor write FAColor;
property Color: TColor read GetColor write SetColor;
end;
procedure Register;
implementation
constructor TIntEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Color := FColor;
end;
destructor TIntEdit.Destroy;
begin
inherited Destroy;
end;
procedure TintEdit.CMColorChanged(var Message: TMessage);
begin
inherited;
FBrush.Color := FColor;
NotifyControls(CM_PARENTCOLORCHANGED);
end;
procedure TIntEdit.SetAcolor(Value: string);
begin
FAcolor := Value;
end;
function TIntEdit.GetAColor: string;
begin
if FInputType = isDatetime then
begin
FColor := ClWhite;
Result := 'Clwhite';
end;
if FInputType = isFloat then
begin
FColor := clred;
Result := 'ClRed';
end;
if FInputType = isInteger then
begin
FColor := Clblue;
Result := 'ClBlue';
end;
if FInputType = isString then
begin
Fcolor := ClGreen;
Result := 'ClGreen';
end;
end;
procedure TintEdit.setcolor(Value: TColor);
begin
if FColor <> Value then
begin
FColor := Value;
Perform(CM_COLORCHANGED, 0, 0);
end;
end;
function TIntEdit.GetColor: TColor;
begin
if FInputType = isDatetime then
Result := Clwhite;
if FInputType = isFloat then
Result := ClRed;
if FInputType = isInteger then
Result := ClBlue;
if FInputType = isString then
Result := ClGreen;
end;
procedure Register;
begin
RegisterComponents('Standard', [TIntEdit]);
end;
end.
----------------测试源码-----------------------
unit IntEdit;
interface
uses
SysUtils, Classes, Controls, StdCtrls, Graphics, Messages;
type
TInType = (IsDatetime, IsFloat, IsInteger, IsString);
type
TStyleOption = (Flat, UseLabel);
type
TStyleOptions = set of TStyleOption;
type
TIntEdit = class(TEdit)
private
{ Private declarations }
FInputType: TInType;
FStyleOptions: TStyleOptions;
FAColor: string;
FColor: TColor;
FBrush:TBrush;
procedure SetAcolor(Value: string);
function GetAColor: string;
procedure setcolor(Value: TColor);
function GetColor: TColor;
procedure CMColorChanged(var Message: TMessage); message CM_ColorChanged;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property InputType: TInType read FInputType write FInputType;
property Options: TStyleOptions read FStyleOptions write FStyleOptions;
property InColor: string read GetAColor write FAColor;
property Color: TColor read GetColor write SetColor;
end;
procedure Register;
implementation
constructor TIntEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Color := FColor;
end;
destructor TIntEdit.Destroy;
begin
inherited Destroy;
end;
procedure TintEdit.CMColorChanged(var Message: TMessage);
begin
inherited;
FBrush.Color := FColor;
NotifyControls(CM_PARENTCOLORCHANGED);
end;
procedure TIntEdit.SetAcolor(Value: string);
begin
FAcolor := Value;
end;
function TIntEdit.GetAColor: string;
begin
if FInputType = isDatetime then
begin
FColor := ClWhite;
Result := 'Clwhite';
end;
if FInputType = isFloat then
begin
FColor := clred;
Result := 'ClRed';
end;
if FInputType = isInteger then
begin
FColor := Clblue;
Result := 'ClBlue';
end;
if FInputType = isString then
begin
Fcolor := ClGreen;
Result := 'ClGreen';
end;
end;
procedure TintEdit.setcolor(Value: TColor);
begin
if FColor <> Value then
begin
FColor := Value;
Perform(CM_COLORCHANGED, 0, 0);
end;
end;
function TIntEdit.GetColor: TColor;
begin
if FInputType = isDatetime then
Result := Clwhite;
if FInputType = isFloat then
Result := ClRed;
if FInputType = isInteger then
Result := ClBlue;
if FInputType = isString then
Result := ClGreen;
end;
procedure Register;
begin
RegisterComponents('Standard', [TIntEdit]);
end;
end.