I have problem with long time drawing controls in my smart device project.
Here is code that freeze application for ~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);
This time is measure from line SAdr = this.ExecuteSQL("select * from dba." + table);
to line with panelCenter.Controls.Clear();
.
Any ideas how to improve this code?