Winfrom 向panel控件添加指定行列的控件

最近用到了這個功能 就總結一段代碼,建議panel控件使用此FlowLayoutPanel 控件

 private int col = 2;
 private int row = 2;  
 private void InitPnl()
        {
            flpHoldPatients.Controls.Clear();
            var height = flpHoldPatients.Height / row;
            var width = flpHoldPatients.Width / col - 2 * col;
            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    var uc = new UcPatient();
                    uc.Height = height;
                    uc.Width = width;
                    uc.Margin = new System.Windows.Forms.Padding(0, 0, 2, 0);
                    uc.Location = new Point(j * width, i * height);
                    flpHoldPatients.Controls.Add(uc);
                }
            }
        }

  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章