Improving performance of tablelayoutpanel

2019-06-04 00:47发布

问题:

I am using tablelayoutpanelin my WinForm project, it responds slowly to events. I referred to this link to make tablelayoutpanel render faster.

In my code, all the cells in tablelayoutpanel are of equal size(100%), I have added a picturebox in each cell and it's SizeMode property to stretch.The number of cells are just 9 and when i resize the panel it is slow.
The code is as shown below. If i create 300 cells it takes 4 seconds to resize.

Void change_tableLayout(int num) //num =9
 {
     CoTableLayoutPanel ctlp = gcnew CoTableLayoutPanel(); //inherited tablelayoutpanel as described in above link
     global_ctlp.Cursor = System.Windows.Forms.Cursors.WaitCursor;     
     num = Math.Sqrt(num);
     global_ctlp.Controls.Clear();
     global_ctlp.RowStyles.Clear();
     global_ctlp.ColumnCount = num;
     global_ctlp.RowCount = num;
         for(int i = 0; i < num; i++) //row cell
             {
                 RowStyle rs = gcnew RowStyle(SizeType::Percent, 50);
                 global_ctlp.RowStyles.Add(rs);
                    for (int j = 0; j < num; j++) //column cell
                       {
                         global_ctlp.ColumnStyles.Add(gcnew ColumnStyle(SizeType.Percent, 50));
                         PictureBox pictureBox1 = gcnew PictureBox();
                         pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
                         pictureBox1.Image = Image.FromFile("image_path");
                         global_ctlp.Controls.Add(pictureBox1, i, j);
                         pictureBox1.Margin = System.Windows.Forms.Padding(0);
                         pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
                     }
             }
     global_ctlp.Cursor = System.Windows.Forms.Cursors.Default;
 }

Can this be improved further. How do i make this faster? or Is there any better component other than tablelayoutpanel.