26-02-2023, 12:50 PM
قمت بالتعديل عليه ليتسنى استعماله بطرية سهلة ,,,,
المهم يجب دائما اضافة CustomCaptionPanel بعد ExtCtrls حتى يتم تحويل Panel العادي الى هذا النوع الجديد
انظر الى الملف المرفق,,,
المهم يجب دائما اضافة CustomCaptionPanel بعد ExtCtrls حتى يتم تحويل Panel العادي الى هذا النوع الجديد
انظر الى الملف المرفق,,,
كود :
unit CustomCaptionPanel;
interface
uses
Windows, SysUtils, Classes, Controls, Graphics, ExtCtrls;
type
TPanel = class(ExtCtrls.TPanel)
private
FEnableHeader :boolean;
{ Private declarations }
FBorderColor: TColor;
FBorderRadius: integer;
procedure SetBorderColor(BorderColor: TColor);
procedure SetBorderRadius(BorderRadius: integer);
procedure SetEnableHeader(const Value: boolean);
protected
{ Protected declarations }
procedure Paint; override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
property BorderColor: TColor read FBorderColor write SetBorderColor;
property BorderRadius: integer read FBorderRadius write SetBorderRadius;
property EnableHeader:boolean read FEnableHeader write SetEnableHeader;
end;
implementation
{ TCustomCaptionPanel }
constructor TPanel.Create(AOwner: TComponent);
begin
inherited;
FBorderColor := $0033CCFF;;
FBorderRadius := 16;
end;
procedure TPanel.Paint;
var
r: TRect;
const
Alignments: array[TAlignment] of integer = (DT_LEFT, DT_RIGHT, DT_CENTER);
begin
if not FEnableHeader then
begin
inherited;
Exit;
end;
Canvas.Pen.Color := FBorderColor;
Canvas.Brush.Color := FBorderColor;
Canvas.Brush.Style := bsSolid;
Canvas.FillRect(Rect(FBorderRadius,
0,
ClientWidth - FBorderRadius,
FBorderRadius));
Canvas.Ellipse(Rect(0,
0,
2*FBorderRadius,
2*FBorderRadius));
Canvas.Ellipse(Rect(ClientWidth - 2*FBorderRadius,
0,
ClientWidth,
2*FBorderRadius));
Canvas.Brush.Color := Color;
Canvas.Rectangle(Rect(0,
FBorderRadius,
ClientWidth,
ClientHeight));
Canvas.Font.Assign(Self.Font);
r := Rect(FBorderRadius, 0, ClientWidth - FBorderRadius, FBorderRadius);
Canvas.Brush.Style := bsClear;
DrawText(Canvas.Handle,
PChar(Caption),
length(Caption),
r,
DT_SINGLELINE or DT_LEFT or DT_VCENTER or DT_END_ELLIPSIS or Alignments[Alignment]);
end;
procedure TPanel.SetBorderColor(BorderColor: TColor);
begin
if FBorderColor <> BorderColor then
begin
FBorderColor := BorderColor;
Invalidate;
end;
end;
procedure TPanel.SetBorderRadius(BorderRadius: integer);
begin
if FBorderRadius <> BorderRadius then
begin
FBorderRadius := BorderRadius;
Invalidate;
end;
end;
procedure TPanel.SetEnableHeader(const Value: boolean);
begin
FEnableHeader := Value;
if FEnableHeader then
BevelOuter :=bvNone
else
BevelOuter :=bvRaised;
Invalidate;
end;
end.

![[-]](https://delphi4arab.net/forum/D4A2020/collapse.png)