弹出窗口问题 ( 积分: 0 )

  • 主题发起人 主题发起人 killjava
  • 开始时间 开始时间
K

killjava

Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button3Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

type

TPopupcontrol = class(TCustomcontrol)
private
protected
procedure Paint; override;
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
end;

procedure TPopupcontrol.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do begin
ExStyle := WS_EX_TOOLWINDOW or WS_EX_CONTROLPARENT;
AddBiDiModeExStyle(ExStyle);
WindowClass.style := CS_SAVEBITS;
end;
end;

procedure TPopupcontrol.CreateWnd;
begin
inherited CreateWnd;
Windows.SetParent(Handle, 0);
CallWindowProc(DefWndProc, Handle, wm_SetFocus, 0, 0);
end;

procedure TPopupcontrol.Paint;
begin
Canvas.Brush.Color := clRed;
Canvas.FillRect(Canvas.ClipRect);
end;

var
c : TPopupcontrol;

procedure TForm1.Button3Click(Sender: TObject);
begin
Showmessage('ccc');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
c := TPopupcontrol.Create(Self);
c.Parent := Self;
c.SetBounds(10, 10, 100, 100);
Button3.Parent := c;
Button3.SetBounds(20, 20, 50, 20);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
c.Free;
end;

end.
如何让 Button3 有反应?要能控制 Form1。
 
不会,帮你顶
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TPopupcontrol = class(TCustomForm)
private
protected
procedure Paint; override;
constructor CreateNew(AOwner: TComponent; Dummy: Integer = 0); override;
end;

TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
c : TPopupcontrol;


implementation

{$R *.dfm}

constructor TPopupcontrol.CreateNew(AOwner: TComponent; Dummy: Integer);
begin
inherited;
BorderStyle := bsNone;
end;

procedure TPopupcontrol.Paint;
begin
Canvas.Brush.Color := clRed;
Canvas.FillRect(Canvas.ClipRect);
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
c := TPopupcontrol.CreateNew(Application);
//c.Parent := Self;
c.SetBounds(10, 10, 100, 100);
c.Visible := True;
Button3.Parent := c;
Button3.SetBounds(20, 20, 50, 20);
Button3.BringToFront;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
c.Free;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
ShowMessage('aaaa');
end;

end.
 
后退
顶部