TTabControl包含一列字符串标签的tabs
每个标签控制一个对象
首先创建一个TForm;接下来添加TTabControl组件和一个文件对话框TOpenDialog(用于添加文件),然后在TTabControl里面添加TMemo(多行文本编辑框),最后在Form上添加一个Button,在Button事件里面添加如下函数
//在创建窗口的时候设置编辑框的滚动条
void __fastcall TForm2::FormCreate(TObject *Sender)
{
//Memo1->ScrollBars = ssHorizontal;
Memo1->ScrollBars = ssBoth;
}
void __fastcall TForm2::Button1Click(TObject *Sender)
{
OpenDialog1->Options << ofAllowMultiSelect << ofFileMustExist << ofHideReadOnly;
if(OpenDialog1->Execute())
{
int index = TabControl1->Tabs->Add(OpenDialog1->FileName);
Memo1->Lines->LoadFromFile(TabControl1->Tabs->Strings[index]);
TabControl1Change(Sender);
}
}
// 通过点击上面的tabs进行
void __fastcall TForm2::TabControl1Change(TObject *Sender)
{
Memo1->Lines->LoadFromFile(TabControl1->Tabs->Strings[TabControl1->TabIndex]);
}