ChrisLM
asked on
Change the color of a TDBEdit when its focused also using XP-Manifest component
Hi,
I want to write a custom component to that is dervied from a TDBEdit so that the color of the TDBEdit changes when it receives focus.
So far I have this:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ------
type
TColorDBEdit = class(TDBEdit)
private
FFocusOnColor: TColor;
FFocusOffColor: TColor;
procedure SetFocusOnColor(Value: TColor);
procedure SetFocusOffColor(Value: TColor);
{ Private declarations }
protected
{ Protected declarations }
procedure CMEnter(var Message: TCMEnter); message CM_ENTER;
procedure CMExit(var Message: TCMExit); message CM_EXIT;
public
{ Public declarations }
published
{ Published declarations }
property FocusOnColor:TColor read FFocusOnColor write SetFocusOnColor;
property FocusOffColor:TColor read FFocusOffColor write SetFocusOffColor;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standa rd', [TColorDBEdit]);
end;
{ TCMEdit }
procedure TColorDBEdit.CMEnter(var Message: TCMEnter);
begin
inherited;
Self.Color := FFocusOnColor;
Self.Invalidate;
end;
procedure TColorDBEdit.CMExit(var Message: TCMExit);
begin
inherited;
Self.Color := FFocusOffColor;
Self.Invalidate;
end;
procedure TColorDBEdit.SetFocusOnCol or(Value: TColor);
begin
if (FFocusOnColor <> Value) then
FFocusOnColor := Value;
end;
procedure TColorDBEdit.SetFocusOffCo lor(Value: TColor);
begin
if (FocusOffColor <> Value) then
FFocusOffColor := Value;
end;
end.
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ------
This code almost works, but for some reason there is a white border inside the blue (XP) border.
The white border doesn't change color until you move the mouse outside the TDBEdit.
The same thing occurs when the control looses focus. A colored border is left until you move outside the control and it returns back to white.
Is there something that I have missed with painting the control?
I'm using Delphi 7 Pro, with an XP-Manifest component on the form.
Regards,
Chris
I want to write a custom component to that is dervied from a TDBEdit so that the color of the TDBEdit changes when it receives focus.
So far I have this:
--------------------------
type
TColorDBEdit = class(TDBEdit)
private
FFocusOnColor: TColor;
FFocusOffColor: TColor;
procedure SetFocusOnColor(Value: TColor);
procedure SetFocusOffColor(Value: TColor);
{ Private declarations }
protected
{ Protected declarations }
procedure CMEnter(var Message: TCMEnter); message CM_ENTER;
procedure CMExit(var Message: TCMExit); message CM_EXIT;
public
{ Public declarations }
published
{ Published declarations }
property FocusOnColor:TColor read FFocusOnColor write SetFocusOnColor;
property FocusOffColor:TColor read FFocusOffColor write SetFocusOffColor;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standa
end;
{ TCMEdit }
procedure TColorDBEdit.CMEnter(var Message: TCMEnter);
begin
inherited;
Self.Color := FFocusOnColor;
Self.Invalidate;
end;
procedure TColorDBEdit.CMExit(var Message: TCMExit);
begin
inherited;
Self.Color := FFocusOffColor;
Self.Invalidate;
end;
procedure TColorDBEdit.SetFocusOnCol
begin
if (FFocusOnColor <> Value) then
FFocusOnColor := Value;
end;
procedure TColorDBEdit.SetFocusOffCo
begin
if (FocusOffColor <> Value) then
FFocusOffColor := Value;
end;
end.
--------------------------
This code almost works, but for some reason there is a white border inside the blue (XP) border.
The white border doesn't change color until you move the mouse outside the TDBEdit.
The same thing occurs when the control looses focus. A colored border is left until you move outside the control and it returns back to white.
Is there something that I have missed with painting the control?
I'm using Delphi 7 Pro, with an XP-Manifest component on the form.
Regards,
Chris
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Russell,
Thank you very much. Greatly appreciated.
Works exactly how I wanted.
Regards,
Chris
Thank you very much. Greatly appreciated.
Works exactly how I wanted.
Regards,
Chris
ASKER
Regards,
Chris