c# - 创建图片框的表格布局面板需要很长时间
问题描述
我正在创建这个图片框(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
{
}
}
有任何想法吗?
解决方案
推荐阅读
- scala - 如果从`stdin`读取并写入`stdout`,如何测试akka actor的行为?
- c# - 如何处理也从 sql 加载的组合框 然后这个组合框从获取数据按钮中接收值
- node.js - MongoDb 匹配未知数量的不同值
- c++ - 如何计算文件中的单词?
- mysql - 当您在 MySQL 工作台中有一个联合键时,如何在不同的行上引用?
- flutter - 为什么单击 TextFormField 会触发 didUpdateWidget()?
- google-apps-script - 无权使用 setFormula Google appScript
- javascript - 将数据 $(form).serialize() 和一个数组一起发布
- ruby-on-rails - 如果不进行保存,我可以查看 ActiveRecord .save 调用会生成什么 SQL 吗?
- tensor - TensorFlow - 仅推断模型的一个子集