C++ builder 中 流式布局 panel块可自动排列

今天领导安排了一项工作,就是在一个窗体界面中显示所有设备的运行概览情况,经过一段时间思考 我决定使用单个窗体来显示一台设备的概览情况(按照标题的意思就是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...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值