关于WinForm控件重绘速度慢的问题
在一个WinForm项目中需要用到座席状态监控,我在一个Panel里放置了几百个控件,每个控件对应一个座席,控件的位置就是座席人员的物理位置,所以在调整Form大小时,控件要按比例的放大和缩小(不能重排,否则位置信息就乱掉了)。
缩放效果(原始):
缩放效果(缩小):
缩放代码如下:
float fWidthRate = (float)this.Size.Width / this._lastSize.Width;
float fHeightRate = (float)this.Size.Height / this._lastSize.Height;
this.toolStripContainer.ContentPanel.Scale(new SizeF(fWidthRate, fHeightRate));
{
factortab2[i++] = (ctr.Location.X) / (float)tabPageTransducerTest.Size.Width;
factortab2[i++] = (ctr.Location.Y) / (float)tabPageTransducerTest.Size.Height;
ctr.Tag = ctr.Size;
}
proptt = factortab2;
private void tabPageTransducerTest_Resize(object sender, EventArgs e)
{
int i = 2;
float[] scale = (float[])proptt;
foreach (Control ctr in this.tabPageTransducerTest.Controls)
{
ctr.Left = (int)(tabPageTransducerTest.Size.Width * scale[i++]);
ctr.Top = (int)(tabPageTransducerTest.Size.Height * scale[i++]);
ctr.Width = (int)(tabPageTransducerTest.Size.Width / (float)scale[0] * ((Size)ctr.Tag).Width);
ctr.Height = (int)(tabPageTransducerTest.Size.Height / (float)scale[1] * ((Size)ctr.Tag).Height);
//每次使用的都是最初始的控件大小,保证准确无误。
}
scale = null;
}
用这个缩放呢,直接修改panel中的缩放