例如:
int RowBedCount=7;// 每行床位数
int BedRowCount=4;// 显示床位行数
int BedWidth;int BedHeight;
public void BedPanelRefresh()
{
Bed bed=new Bed();
if(aryBed.Length == 0)return;
int iPanelScrollWidth = (aryBed.Length > (RowBedCount * BedRowCount))?20:0;//需要考虑到panel的scrollbar的宽度
BedHeight=(this.Height-BedRowCount+1) / BedRowCount;
BedWidth=(this.Width - iPanelScrollWidth - RowBedCount+1) / RowBedCount;
bed.Height = BedHeight;
bed.Width = BedWidth;
for( int i=0;i<aryBed.Length;i++)
{
aryBed[i].Height = BedHeight;
aryBed[i].Width = BedWidth;
if(i<RowBedCount)aryBed[i].Top = 0;
else aryBed[i].Top = aryBed[i-RowBedCount].Top + bed.Height+1; if((i%RowBedCount)==0)aryBed[i].Left = 0;
else aryBed[i].Left = aryBed[i-1].Left + bed.Width+1;
this.plBed.PerformLayout();
}
}

解决方案 »

  1.   

    上面代码的效果在于:在一个Panel里加入一些床位,不论Panel的大小如何变化,它一定显示4行7列的床铺,此时床铺按钮的大小需要进行调整。
      

  2.   

    private void panel1_SizeChanged(object sender, System.EventArgs e)
    {
       //panel1 size改变触发。
       在这里设床的位置大小和panel成1个固定的比例,就行了。
    }
      

  3.   

    control.Location = new Point(int left,int top);
      

  4.   

    我也有这个问题,比如我想在Panel里面添加多个textBox,但是textBox没有top和left 啊?
    而且我想实现换行显示也不知道怎么办!比如我想添加几个后,换一行再添加呢?怎么实现呢?