unit CtrlPanel;
interface
uses
Windows, Classes, Controls, Graphics, Messages, Forms;
type
TControlPanel =
class(TControl)
private
FColorFace: TColor;
FColorLight: TColor;
FColorDark: TColor;
FCanvas: TCanvas;
procedure DrawBevel(Canvas: TCanvas; Rect: TRect; LightColor, DarkColor: TColor);
procedure DrawFrame(Canvas: TCanvas; Offset, FrameWidth: Integer; LightColor, DarkColor: TColor);
protected
public
constructor Create(AOwner: TComponent);
override;
property Canvas: TCanvas
read FCanvas;
procedure Paint;
published
property Visible;
end;
implementation
constructor TControlPanel.Create(AOwner: TComponent);
begin
inherited;
FColorDark:= clBlack;
FColorLight:= clSilver;
FColorFace:= clBtnFace;
FCanvas := TControlCanvas.Create;
TControlCanvas(FCanvas).Control := Self;
end;
procedure TControlPanel.Paint;
var
ScrBmp: TBitmap;
begin
ScrBmp:= TBitmap.Create;
ScrBmp.Width:= ClientWidth;
ScrBmp.Height:= ClientHeight;
ScrBmp.Canvas.Brush.Color := clBtnFace;
ScrBmp.Canvas.FillRect(Rect(0,0,ClientWidth,ClientHeight));
ScrBmp.Canvas.Font:= Font;
ScrBmp.Canvas.Brush.Style:= bsClear;
DrawFrame(ScrBmp.Canvas, 0, 1, FColorLight, FColorDark);
Self.Canvas.Draw(0, 0, ScrBmp);
ScrBmp.Free;
end;
procedure TControlPanel.DrawBevel(Canvas: TCanvas; Rect: TRect; LightColor, DarkColor: TColor);
begin
Canvas.Pen.Width:= 1;
Canvas.Pen.Color:= LightColor;
Canvas.MoveTo(Rect.Left, Rect.Top + Rect.Bottom);
Canvas.LineTo(Rect.Left, Rect.Top);
Canvas.LineTo(Rect.Left + Rect.Right, Rect.Top);
Canvas.Pen.Color:= DarkColor;
Canvas.LineTo(Rect.Left + Rect.Right, Rect.Top + Rect.Bottom);
Canvas.LineTo(Rect.Left, Rect.Top + Rect.Bottom);
end;
procedure TControlPanel.DrawFrame(Canvas: TCanvas; Offset, FrameWidth: Integer; LightColor, DarkColor: TColor);
var
i: integer;
begin
for i := Offset
to Offset + FrameWidth - 1
do
DrawBevel(Canvas, Rect(i, i, ClientWidth - 2 * i - 1, ClientHeight - 2 * i - 1), LightColor, DarkColor);
end;
end.