今天领导安排了一项工作,就是在一个窗体界面中显示所有设备的运行概览情况,经过一段时间思考 我决定使用单个窗体来显示一台设备的概览情况(按照标题的意思就是panle),然后在主界面上排列多个 设备概览界面。然后用c++builder 6/delphi7 的窗口停靠功能再配合窗体的resize事件来实现。先帖代码 主窗体构造函数:
TList *FromList;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
FromList=new TList();
for (int i=0;i<20;i++)
{
TFormSub *tempFrom=new TFormSub(this);
tempFrom->ManualDock(this,this,alClient);
tempFrom->Show();
tempFrom->Panel_Name->Caption=IntToStr(i+1)+"号风机组";
FromList->Add(tempFrom);
}
}
然后在窗体resize事件中添加代码
//---------------------------------------------------------------------------
void __fastcall TForm1::FormResize(TObject *Sender)
{
int mainheit=this->Width;
TFormSub *temp=NULL;
if (FromList->Count>0)
{
temp=(TFormSub *)FromList->Items[0];
}
else
{
return ;
}
int x=GetSystemMetrics(SM_CYHSCROLL); // 水平
int y=GetSystemMetrics(SM_CXVSCROLL); //
int ColCount=(mainheit-x)/temp->Width;
int StartTop=0;
int ControlLeft=0;
int index=0;
while (index<FromList->Count)
{
ControlLeft=0;
for (int j=0;j<ColCount;j++)
{
temp=(TFormSub *)FromList->Items[index];
temp->Top=StartTop-this->VertScrollBar->Position;//如果不加这句,有滚动条时再变化窗体大小会出现窗体上部分都是空的现像。。
temp->Left=ControlLeft;
ControlLeft+=temp->Width;
index++;
if (index==FromList->Count)
{
break ;
}
}
StartTop+=temp->Height;
}
}
//我现在写程序特别喜欢用Tlist.尽量少用vetor...