BCB子窗体的一般操作

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

1、建立主窗口Form1:建立一个新窗口,将其FormStyle设置为fsMDIForm,那么它就是主窗体,即通常所说的父窗口,父窗体是启动的窗体。

2、建立一个新窗口Form2和Form3,将这两个窗体的FormStyle设置为:fsMDIChild

3、进入Project/Options菜单,将Form2和Form3设置为Available forms,这样就不会程序启动时自动创建

4、在Form1中加入这两句,使Form1能调用Form2和Form3类来创建窗体对象:

#include "Unit2.h"

#include "Unit3.h"

5、在Form2和Form3的OnClose事件中设置如下语句,以能够关闭程序:

void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)

{

Action=caFree;

}

///////////////////////////////////////////////////////////////////////////////////////////////////////

void __fastcall TForm3::FormClose(TObject *Sender, TCloseAction &Action)

{

Action=caFree;

}

////////////////////////////////////////////////////////////////////////////////

6、在Form1窗体中创建Form2和Form3的方法:

TForm2 *wnd;

wnd=new TForm2(Application);

wnd->Caption ="我的子窗体2";

///////////////////////////////////////////////////////////////////////////////

TForm3 *wnd;

wnd=new TForm3(Application);

wnd->Caption ="我的子窗体3";

///////////////////////////////////////////////////////////////////////////////

7、查看已创建了的子窗体的方法:

int i;

for(i=0;i<MDIChildCount;i++)

{

file://子窗体要生成了才能找到

ShowMessage(MDIChildren[i]->Caption);

}

//////////////////////////////////////////////////////////////////////////////

8、在创建Form2之前,先把所有的子窗体都关闭的方法:

TForm2 *wnd;

for(int i=0;i<MDIChildCount;i++)

{

MDIChildren[i]->Close();

}

wnd=new TForm2(Application);

wnd->Caption="我的子窗体2";

///////////////////////////////////////////////////////////////////////////

正文

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有  導航