我正在创建该图像框的表格布局面板(66x66像素),在一台PC上花费不到一秒钟的时间来完成,而在另一台PC上(具有相同功能...)花费了大约8秒。 我必须在运行时创建图形,因为我只在运行时知道需要放置哪些图像。
这是功能:
private void InitializeDrawerCells(int cabinetPartID, int drawerID)
{
PictureBox pb;
try
{
tblDrawerCells.RowStyles.Clear();
tblDrawerCells.ColumnStyles.Clear();
tblDrawerCells.Controls.Clear();
tblDrawerCells.RowCount = 12;
tblDrawerCells.ColumnCount = 16;
for (int i = 0; i < tblDrawerCells.RowCount; i++)
{
RowStyle style = new RowStyle
{
SizeType = SizeType.Absolute,
Height = tblDrawerCells.Height / tblDrawerCells.RowCount
};
tblDrawerCells.RowStyles.Add(style);
}
for (int i = 0; i < tblDrawerCells.ColumnCount; i++)
{
ColumnStyle style = new ColumnStyle
{
SizeType = SizeType.Absolute,
Width = tblDrawerCells.Width / tblDrawerCells.ColumnCount
};
tblDrawerCells.ColumnStyles.Add(style);
}
for (int i = 0; i < tblDrawerCells.ColumnCount; i++)
{
for (int j = 0; j < tblDrawerCells.RowCount; j++)
{
pb = new PictureBox();
if (_DrawerType == eDrawerType.Regular)
{
if (Scenraio == OpenCabinetScenario.Maintenance)
{
if (NarcoticsCabinetManager.CabinetParts[_CurrentCabPartID].Drawers[_DrawerNumber - 1].DrawerType == eDrawerType.Regular)
pb.BackgroundImage = ImageOn[tblDrawerCells.RowCount - j - 1][i];
else
pb.BackgroundImage = ImageReturnOff;
}
else
pb.BackgroundImage = ImageOff;
}
else
pb.BackgroundImage = global::NarcoticsStorageSystem2.Properties.Resources._11x6_Cells;
pb.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
// pb.Dock = System.Windows.Forms.DockStyle.Fill;
pb.Location = new System.Drawing.Point(0, 0);
pb.Margin = new System.Windows.Forms.Padding(0, 0, 0, 0);
if (_DrawerType == eDrawerType.Regular)
pb.Size = new System.Drawing.Size(66, 66);
else if (_DrawerType == eDrawerType.Return)
pb.Size = new System.Drawing.Size(198, 66);
// if (_Scenraio == OpenCabinetScenario.FillItems)
// {
pb.Click += new System.EventHandler(this.pbCell_Click);
// }
pb.TabStop = false;
pb.Tag = new Tuple<int, int, int, int>(_DrawerNumber, tblDrawerCells.RowCount - j, i + 1, (int)ImageType.Off);
tblDrawerCells.Controls.Add(pb, i, j);
}
}
}
catch (Exception ex)
{
//add ex to log...
}
finally
{
}
}
有什么想法吗?