Hola...
Prueba este código y me dices que tal...
Código Delphi
[-]
unit UCCDShadow;
interface
uses
Windows, Messages, SysUtils, Controls, ComCtrls,Classes, Forms, Graphics;
type
TCCDShadow = class(TComponent)
private
FActive: Boolean;
FDeph: Integer;
FColor: Tcolor;
ParentForm: TForm;
procedure SetActive(Value: Boolean);
procedure Setdeph(value : Integer);
procedure Setcolor(Value: TColor);
protected
procedure ShadowDraw;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
constructor Create(AOwner: TComponent); override;
published
property Active: Boolean read FActive write SetActive default True;
property Deph: Integer read FDeph write SetDeph default 3;
property Color: Tcolor read FColor write SetColor default clAqua;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('CLub Delphi', [TCCDShadow]);
end;
constructor TCCDShadow.Create(AOwner: TComponent);
var
I: Integer;
begin
if not (AOwner is TForm) then
raise Exception.Create('The owner must be a Form');
ParentForm := TForm(AOwmer);
for I := 0 to Pred(ParentForm.ComponentCount) do
if ParentForm.Components[i] is TCCDShadow then
raise Exception.Create('Only one TCCDShadow can exist in a Form');
inherited Create(AOwner);
Fcolor := clAqua;
Fdeph := 3;
FActive := True;
ShadowDraw
end;
procedure TCCDShadow.SetActive(Value: Boolean);
begin
if FActive <> Value then
begin
FActive := Value;
ShadowDraw
end
end;
Procedure TCCDShadow.SetColor(value : TColor);
begin
if (FColor <> value) then
begin
FColor:= value;
ShadowDraw
end
end;
procedure TCCDShadow.SetDeph(value : Integer);
begin
if (Fdeph <> value) then
begin
FDeph:= value;
ShadowDraw
end
end;
procedure TCCDShadow.ShadowDraw;
var
I: Integer;
rect: TRect;
old: TColor;
Component : TComponent;
begin
if not FActive then
Exit;
ParentForm.Repaint;
for I := 0 to ParentForm.ControlCount -1 do
with ParentForm do
begin
Component:=Components[i];
if Component is TControl then
begin
rect := Controls[i].BoundsRect;
canvas.fillrect(rect);
rect.Left := rect.Left + FDeph;
rect.Top := rect.Top + FDeph;
rect.Right := rect.Right + FDeph;
rect.Bottom := rect.Bottom + FDeph;
old := Canvas.brush.color;
canvas.brush.Color := Fcolor;
canvas.fillrect(rect);
canvas.brush.Color := old;
Controls[i].Repaint
end
end
end;
procedure TCCDShadow.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited Notification(AComponent,Operation);
ShadowDraw;
end;
end.
Si te fijas, le agregué una propiedad llamada
Active para especificar si quieres dibujar o no las sombras...
También, cada que eliminas o agregas un control en la forma, el componente redibuja las sombras...
Otro cambio que tiene es que si el owner del componente no es una forma, te salta un error y también solo puede existir un componente del tipo
TCCDShadow en la forma.
Saludos...