to hb_wshsh
您说的子窗体是什么意思?是mdi窗体还是说你用的是子窗体原理?两种我都试过了。不行
to kiki4
您的方法我试过了。被调用窗体里面的组件一个也显示不出来,为什么啊?是不是还有设置?我的代码如下:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm2 = class(TForm)
Label1: TLabel;
Button1: TButton;
Button2: TButton;
ListBox1: TListBox;
Image1: TImage;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
Image1: TImage;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
procedure OnParentOpenForm(FormClass:TComponentClass;FormName:Tform;ParentName:TWincontrol);
implementation
uses Unit2;
//////////////////////////////////////////////////////////////////////////////
//在指定容器中打开窗体 FormClass 窗体类 一般在 窗体名前面加T
// FormName 窗体名称 ParentName 容器名称
//////////////////////////////////////////////////////////////////////////////
procedure OnParentOpenForm(FormClass:TComponentClass;FormName:Tform;ParentName:TWincontrol);
var
i:integer;
begin
//在打开窗体之前先清空指定容器中的窗体
for i:=0 to Application.ComponentCount-1 do
begin
if Application.Components is tform then
begin
if (Application.Components as tform).Parent=ParentName then
(Application.Components as tform).Free;
end;
end;
//创建并在指定容器中打开窗体
Application.CreateForm(FormClass,FormName); //创建窗体
showmessage('sdfas');
FormName.Parent:=ParentName; //指定窗体容器
FormName.Align:=alClient;
//FormName.BorderStyle:=bsNone;
FormName.Show;
formname.Visible:=true;
end;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
OnParentOpenForm(Tform,form2,panel1);
end;
end.
哪位最终答对了我还会再开一贴给50分。这个帖子大家打过的平分吧。好不好?谢谢各位。。