控件显示(100分)

  • 主题发起人 主题发起人 first
  • 开始时间 开始时间
F

first

Unregistered / Unconfirmed
GUEST, unregistred user!
我在Form1中动态创建一Button,如何在Form2中显示此Button
就是要此Button可以显示在任何Form上
 
呵呵,你可以做成一个控件么,要不然在一个独立的unit中写一个button类
 
有什么用?
 
问得不清楚
 
to pink_wt
如何写能给个例子么?
 
哦,我觉得不难,让我写写
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
uses unit2;
{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
b:Tbutton;
begin
b:=TmyButton.create(self);
b.parent:=form1;
end;

end.


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

type
Tmybutton=class(Tbutton);
var

mybutton :Tmybutton;
implementation

end.

你可以在unit2中加入你所需要的功能

 
to pink_wt
不行呀,
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
List: TList;
end;

var
Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
b:Tbutton;
begin
B := Tmybutton.Create(self);
b.Parent := form1;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
form: tform2;
begin
form := tform2.Create(application);
form.Show;
end;

end.

interface

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

type
Tmybutton=class(Tbutton);
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation

uses Unit1;

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
Tmybutton(form1.List.Items[0]).Parent := form2;//改变父属性
end;
 
那点行不通
 
to pink_wt
你试呀,是读地址错误
 
不会吧,在我这是好的,我用的是delphi6.0 sp2,win2000sp3
 
b.Parent := form2;
b.Parent := formn;
搞定.
 
to 里斯
不行呀,你试过了吗?
b.parent := form2;
b.parent := formn;//不显示b
 
后退
顶部