我在智能设备项目中长时间绘制控件时遇到问题。
这是冻结应用程序的代码~11s
:
SAdr = this.ExecuteSQL("select * from dba." + table);
while (SAdr.Read())
{
PictureBox pBox = new PictureBox();
pBox.Image = Program.ByteArrayToImage((byte[])SAdr["IMGDATA"]);
pBox.Name = String.Format("pictureBox{0}#{1}",nameKey ,Int16.Parse(SAdr[colName].ToString()));
pBox.Width = pBox.Height = size;
pBox.Left = marginL;
pBox.Top = marginT;
pBox.SizeMode = PictureBoxSizeMode.StretchImage;
pBox.Click += new EventHandler(pBoxTow_Click);
if (counter < cols)
marginL += size + space;
else
{
marginL = 10;
marginT += size + space;
counter = 0;
}
panel.Controls.Add(pBox);
counter++;
}
panelCenter.Controls.Clear();
panelCenter.Controls.Add(panel);
这个时间是逐行测量SAdr = this.ExecuteSQL("select * from dba." + table);
的panelCenter.Controls.Clear();
。
任何想法如何改进此代码?