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 button();
                   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);
               }
           }
       }

 

 

 

转 : https://www.cnblogs.com/Angel-szl/p/12856100.html

posted @ 2021-06-08 09:53  与f  阅读(193)  评论(0编辑  收藏  举报