unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TMyPanel =
class(TPanel)
private
procedure WMEraseBkgnd(
var Msg: TWMEraseBkgnd);
message WM_ERASEBKGND;
protected
procedure CreateParams(
var Params: TCreateParams);
override;
procedure Paint;
override;
public
published
end;
TForm1 =
class(TForm)
Image1: TImage;
procedure FormShow(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
MyPanel: TMyPanel;
Edit1: TEdit;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses Themes;
procedure TMyPanel.CreateParams(
var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle := Params.ExStyle
or WS_EX_TRANSPARENT;
end;
procedure TMyPanel.WMEraseBkgnd(
var Msg: TWMEraseBkgnd);
begin
Msg.Result := 1;
end;
procedure TMyPanel.Paint;
const
Alignments:
array[TAlignment]
of Longint = (DT_LEFT, DT_RIGHT, DT_CENTER);
VerticalAlignments:
array[TVerticalAlignment]
of Longint = (DT_TOP, DT_BOTTOM, DT_VCENTER);
var
Rect: TRect;
TopColor, BottomColor: TColor;
// FontHeight: Integer;
Flags: Longint;
procedure AdjustColors(Bevel: TPanelBevel);
begin
TopColor := clBtnHighlight;
if Bevel = bvLowered
then TopColor := clBtnShadow;
BottomColor := clBtnShadow;
if Bevel = bvLowered
then BottomColor := clBtnHighlight;
end;
begin
Rect := GetClientRect;
if BevelOuter <> bvNone
then
begin
AdjustColors(BevelOuter);
Frame3D(Canvas, Rect, TopColor, BottomColor, BevelWidth);
end;
{if not (ThemeServices.ThemesEnabled and (csParentBackground in ControlStyle)) then
Frame3D(Canvas, Rect, Color, Color, BorderWidth)
else}
InflateRect(Rect, -BorderWidth, -BorderWidth);
if BevelInner <> bvNone
then
begin
AdjustColors(BevelInner);
Frame3D(Canvas, Rect, TopColor, BottomColor, BevelWidth);
end;
with Canvas
do
begin
{if not ThemeServices.ThemesEnabled or not ParentBackground then
begin
Brush.Color := Color;
FillRect(Rect);
end;}
Brush.Style := bsClear;
Font := Self.Font;
Flags := DT_EXPANDTABS
or DT_SINGLELINE
or
VerticalAlignments[VerticalAlignment]
or Alignments[Alignment];
Flags := DrawTextBiDiModeFlags(Flags);
DrawText(
Handle, PChar(Caption), -1, Rect, Flags);
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Edit1.Free;
MyPanel.Free;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
MyPanel := TMyPanel.Create(Self);
MyPanel.Parent := Self;
MyPanel.Color := clRed;
MyPanel.BorderWidth := 5;
MyPanel.SetBounds(50, 50, ClientWidth-100, ClientHeight-100);
MyPanel.BevelOuter := bvRaised;
MyPanel.BevelInner := bvLowered;
Edit1 := TEdit.Create(Self);
Edit1.Parent := MyPanel;
Edit1.Text := '
Hello there !';
Edit1.SetBounds(50, 50, 150, 21);
end;
end.