ick
全选 Selectall1Click
其他:靠左 Left1Click
靠右 Left1Click
居中 Left1Click
自动换行 Wordwrap1Click
字体 Font1Click
(9) 从Dialogs控件板选取对话框控件到ChildForm上,并设置其属性:
* SaveDialog
Name SaveFileDialog
单击Filter属性,弹出Filter Editor对话框,输入:
Rich Text Format(*.rtf) *.rtf
Text Files(*.txt) *.txt
All Files(*.*) *.*
* PrintDialog
Name PrintDialog1
* PrinterSetupDialog
Name PrinterSetupDialog1
* FontDialog
Name FontDialog1
(10) 然后从Win32控件板中选择RichEdit控件,放在ChildForm上,设置其属性:
Align alClient
Name doc
点击Lines属性,弹出String list editor,清空里面的内容。
(11) 最后,在程序中加入程序源代码。运行该程序,然后打开两个文档(该程序在C++ Builder 3.0和Windows 95下调试通过):
附源程序清单:
(这儿略去大部分系统自己加进去的程序代码部分):
//-------- MDIMain.cpp-------- #include "MDIMain.h" #include "MDIChild.h" __fastcall TFrameForm::TFrameForm(TComponent* Owner) : TForm(Owner) { } void __fastcall TFrameForm::Exit1Click(TObject *Sender) {Close();//应用程序退出} void __fastcall TFrameForm::Tile1Click(TObject *Sender) {Tile();//窗口层叠} void __fastcall TFrameForm::Cascade1Click(TObject *Sender) {Cascade();//窗口平铺} void __fastcall TFrameForm::Arrangeicons1Click(TObject *Sender) { ArrangeIcons();//排列图标} //新建文档 void __fastcall TFrameForm::New1Click(TObject *Sender) { ChildForm = new TChildForm(this); } //打开文件 void __fastcall TFrameForm::Open1Click(TObject *Sender) { if(OpenFileDialog->Execute()){ ChildForm=new TChildForm(this); ChildForm->Open(OpenFileDialog->FileName); } } //----------MDIChild.cpp------------- #include "MDIChild.h" #include "MDIFrame.h" TChildForm *ChildForm; //定义缺省文件名为Untitled const AnsiString DefaultFileName = AnsiString("Untitled"); __fastcall TChildForm::TChildForm(TComponent* Owner) : TForm(Owner) { } //文件打开函数 void __fastcall TChildForm::Open(const AnsiString AFileName) { PathName = AFileName; Caption = ExtractFileName(AFileName); doc->Lines->LoadFromFile(PathName); doc->SelStart = 0; doc->Modified = false; } void __fastcall TChildForm::New1Click(TObject *Sender) { FrameForm->New1Click(Sender); //新建文件} void __fastcall TChildForm::Open1Click(TObject *Sender) { FrameForm->Open1Click(Sender);//打开文件 } void __fastcall TChildForm::Close1Click(TObject *Sender) { Close();//关闭打开的文件} void __fastcall TChildForm::Exit1Click(TObject *Sender) { FrameForm->Exit1Click(Sender);//退出应用程序 } //保存打开或创建的文档 void __fastcall TChildForm::Save1Click(TObject *Sender) { if(Caption == DefaultFileName){ Saveas1Click(Sender); } else{ doc->Lines->SaveToFile(PathName); doc->Modified = false; } } //另存打开或创建的文档 void __fastcall TChildForm::Saveas1Click(TObject *Sender) { SaveFileDialog->FileName = PathName; if (SaveFileDialog->Execute() ){ PathName= SaveFileDialog->FileName; Caption = ExtractFileName(PathName); Save1Click(Sender); } } //文档打印 void __fastcall TChildForm::Print1Click(TObject *Sender) { if (PrintDialog1->Execute()){
|