Poser un composant sur un control et attachement a un autre
Bonjour,
J'ai fait le code ci dessous pour un Panel avec les coins arrondies.
Il fonctionne, sauf que lorsque je le pose sur un control dans une fenetre, il prends toujours comme control parent la MainForm.
Je ne peux donc le déposer sur une pagecontrol par exemple au sur un autre panel.
En dynamique, lorsque j'affecte le parent, pas de probleme ??
Avez-vous une idée ?
Merci.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| TPanelArrondie = class(TPanel)
private
FRoundRect : boolean;
FArrondieValue,FContourWidth : integer;
FContourColor : Tcolor;
procedure SetRoundRect(Value : boolean);
procedure SetArrondieValue(value : integer);
procedure SetContourColor(Value : Tcolor);
procedure SetContourWidth(value : integer);
protected
{ Protected declarations }
procedure Paint;override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy;override;
published
property RoundRect : boolean read FRoundRect write SetRoundRect;
property ArrondieValue : integer read FArrondieValue write SetArrondieValue;
property ContourColor : Tcolor read FContourColor write SetContourColor;
property ContourWidth : integer read FContourWidth write SetContourWidth;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Supplément', [TPanelArrondie]);
end;
//********************************************************
constructor TPanelArrondie.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Parent := TWinControl(AOwner);
usedockmanager := true;
BevelOuter := bvNone;
RoundRect := true;
ArrondieValue := 10;
DoubleBuffered := true;
color := clSkyBlue;
ContourColor := clblue;
ContourWidth :=1;
//code
end;
//********************************************************
destructor TPanelArrondie.Destroy;
begin
//code
inherited Destroy;
end;
//********************************************************
procedure TPanelArrondie.Paint;
var
Rect: TRect;
begin
inherited Paint();
Rect := GetClientRect;
Canvas.Pen.Color := FContourColor;
Canvas.Pen.Width := FContourWidth;
Canvas.Brush.Color := Parent.Brush.Color;
Canvas.FillRect( Rect );
Canvas.Brush.Color := Color;
if ( FRoundRect ) then
begin
Canvas.RoundRect( Rect.Left, Rect.Top,
Rect.Right, Rect.Bottom , FArrondieValue, FArrondieValue );
end
else
Canvas.Rectangle( Rect.Left, Rect.Top,Rect.Right, Rect.Bottom);
end;
//********************************************************
procedure TPanelArrondie.SetRoundRect(Value : boolean);
begin
FRoundRect := Value;
paint;
end;
//********************************************************
procedure TPanelArrondie.SetArrondieValue(value : integer);
begin
FArrondieValue :=value;
paint;
end;
//********************************************************
procedure TPanelArrondie.SetContourColor(Value : Tcolor);
begin
FContourColor := Value;
paint;
end;
//********************************************************
procedure TPanelArrondie.SetContourWidth(value : integer);
begin
FContourWidth := Value;
paint;
end;
//******************************************************** |