unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Buttons, Vcl.StdCtrls;
type TButtonX =class(Vcl.StdCtrls.TButton)
private
var FParent : TWinControl ;
procedure SetParent(AParent: TWinControl);
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
procedure CreateWindowHandle(const Params: TCreateParams);override;
public
constructor Create(AOwner: TComponent); override;
//published property Parent : TWinControl read FParent write SetParent;
end;
type
TForm2 = class(TForm)
SpeedButton1: TSpeedButton;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
// BY SMP3 .
{$R *.dfm}
var s:TButtonX ;
procedure TForm2.Button1Click(Sender: TObject);
begin
s:=TButtonX.Create(self);
s.Left:=0;
s.Top:=0;
s.Parent:=self;
end;
procedure TForm2.SpeedButton1Click(Sender: TObject);
begin
end;
{ TButton }
constructor TButtonX.Create(AOwner: TComponent);
begin
inherited;
Caption:=Self.ToString;
Width:=100;
Height:=30;
end;
procedure TButtonX.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style:=WS_POPUP ;
Params.ExStyle := Params.ExStyle or WS_EX_LAYERED;
end;
procedure TButtonX.CreateWindowHandle(const Params: TCreateParams);
begin
inherited CreateWindowHandle(Params);
SetLayeredWindowAttributes(Handle,ColorToRGB($0000FF00), 200, LWA_COLORKEY or LWA_ALPHA);
end;
procedure TButtonX.CreateWnd;
begin
inherited;
end;
procedure TButtonX.SetParent(AParent: TWinControl);
begin
if AParent <> FParent then begin
FParent:=AParent;
// Left := Left + AParent.Left ;
//Top := Top + AParent.Top;
end;
end;
end.