unit Panel;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.ExtCtrls,
Vcl.ImgList;
type
TPanel =
class(
Vcl.ExtCtrls.TPanel)
private { Private-Deklarationen }
FOnPaint: TNotifyEvent;
protected { Protected-Deklarationen }
procedure Paint;
override;
public
{ Public-Deklarationen }
property Canvas;
published { Published-Deklarationen }
property OnPaint: TNotifyEvent
read FOnPaint
write FOnPaint;
end;
type
TForm1 =
class(TForm)
Panel1: TPanel;
procedure FormCreate(Sender: TObject);
procedure Panel1Click(Sender: TObject);
private
{ Private-Deklarationen }
procedure OnPanel1Paint(Sender: TOBject);
public
//procedure FormCreate(Sender: TObject);
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Panel1Click(Sender: TObject);
const
bgcolor = $00FF0000;
//$00FFDDEE;
linecolor = $00FFFFFF;
//$00554366;
var
img:
array of TImage;
reg: hrgn;
i: Integer;
begin
for i := 0
to ComponentCount - 1
do
begin
if Components[i].ClassName = '
TPanel'
then
begin
setlength(img, Length(img) + 1);
img[i] := TImage.Create(Self);
img[i].Width := (Components[i]
as TPanel).Width;
img[i].Height := (Components[i]
as TPanel).Height;
img[i].Parent := (Components[i]
as TPanel);
img[i].Canvas.Brush.Color :=bgcolor;
img[i].Canvas.pen.Color := bgcolor;
img[i].Canvas.Rectangle(5,5,img[i].Width, img[i].Height);
img[i].Canvas.pen.Color :=linecolor;
img[i].Canvas.RoundRect(0,0,img[i].Width - 50,img[i].Height - 5,20,20);
reg := CreateRoundRectRgn(0,0,(Components[i]
as TPanel).Width,
(Components[i]
as TPanel).Height, 0,0);
setwindowrgn((Components[i]
as TPanel).Handle, reg, True);
deleteobject(reg);
end;
end;
end;
procedure TPanel.Paint;
begin
inherited;
if assigned(fOnPaint)
then
fOnPaint(Self);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Panel1.OnPaint := OnPanel1Paint;
end;
procedure TForm1.OnPanel1Paint(Sender: TOBject);
var r: Trect;
begin
r := Panel1.ClientRect;
InflateRect(r, -2, -2);
With Panel1
do
begin
Canvas.Brush.Color :=$CD0000;
//clWindow;
Canvas.RoundRect(r.Left, r.Top, r.Right, r.Bottom, 20, 20);
Canvas.Brush.Color := Panel1.Color;
Canvas.Draw(5, 5, Application.Icon);
Canvas.Brush.Color := $FFFFE0;
Canvas.RoundRect(r.Left, r.Top, r.Right-120, r.Bottom, 30, 30);
Canvas.Brush.Color:=Panel1.Color;
Canvas.Draw(5, 5, Application.Icon);
end;
end;
end.