提高tablelayoutpanel的性能

时间:2017-04-04 05:09:42

标签: c# .net winforms tablelayoutpanel

我在WinForm项目中使用tablelayoutpanel,它对事件响应缓慢。我提到了此link以使tablelayoutpanel渲染得更快。

在我的代码中,tablelayoutpanel中的所有单元格大小相同(100%),我在每个单元格中添加了picturebox 并且它是 SizeMode 属性。单元格的数量仅为9,当我调整面板大小时,它很慢。
代码如下所示。如果我创建300个单元格,则需要4秒钟来调整大小。

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;
 }

可以进一步改进吗?我如何让这更快?或除tablelayoutpanel以外是否有更好的组件。

0 个答案:

没有答案