Convertir un TColor en RGB et vice-versa (2)

type
TTabsheet = class( ComCtrls.TTabSheet )
private
FColor: TColor;
Procedure SetColor( value: TColor );
Procedure WMEraseBkGnd( var msg: TWMEraseBkGnd );
message WM_ERASEBKGND;
public
Constructor Create( aOwner: TComponent ); override;
property Color: TColor read FColor write SetColor;
end;

{...}
implementation
{...}

const ructor TTabsheet.Create(aOwner: TComponent);
begin
inherited;
FColor := clBtnFace;
end;

procedure TTabsheet.SetColor(value: TColor);
begin
If FColor <> value Then Begin
FColor := value;
Invalidate;
End;
end;

procedure TTabsheet.WMEraseBkGnd( var msg: TWMEraseBkGnd);
begin
If FColor = clBtnFace Then
inherited
Else Begin
Brush.Color := FColor;
Windows.FillRect(msg.dc, Clientrect, Brush.handle);
msg.result := 1;
End;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Tabsheet1.color := clWhite;
TabSheet2.color := clLime;
end;

// PageControl1.OwnerDraw := true !

procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl;
TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
AText: string;
APoint: TPoint;
begin
with (Control as TPageControl).Canvas do
begin
Brush.Color := clred;
FillRect(Rect);
AText := TPageControl(Control).Pages[TabIndex].Caption;
with Control.Canvas do
begin
APoint.x := (Rect.Right - Rect.Left) div 2 - TextWidth (AText) div 2;
APoint.y := (Rect.Bottom - Rect.Top) div 2 - TextHeight (AText) div 2;
TextRect(Rect, Rect.Left + APoint.x, Rect.Top + APoint.y, AText);
end;
end;
end;







Ajouter un commentaire
Pseudo
Adresse email
Site internet (optionnel)
Votre commentaire
Fiche de l'article
Mise a jour30/11/2001
VisualisationVu 1280 fois
PublicInternaute zz
CategorieDelphi - Trucs et astuces - Objet
Auteur de l'article
GIS L.L.C.,2000 GIS L.L.C.,2000
connecté le 02/11/2011
1 articles dans la section
Contacter l'auteur