vb.net花了太多时间加载包含Label控件数组的用户控件

时间:2011-12-22 09:20:03

标签: vb.net vb6-migration

升级用户控制从vb6到vb.net 在vb6应用程序中,我使用标签控件数组加载3000个标签 在vb.net中我也是这样做的,但加载时间太长 在vb6中它需要1-2秒,但在vb.net中,相同的工作需要30-40秒 有什么问题?为什么在vb.net中花费太多时间进行同样的工作?

下面给出了代码,这里Led是标签控件数组。

For l = 1 To 3000
  Led.Load(ledCounter)
  ColLed.Add(Led(ledCounter))
  Led(ledCounter).BackColor = System.Drawing.ColorTranslator.FromOle(LedColor)
  Led(ledCounter).Top = VB6.TwipsToPixelsY(15)
  Led(ledCounter).Left = VB6.TwipsToPixelsX(15)
  Led(ledCounter).Height = VB6.TwipsToPixelsY(LedHeight)
  Led(ledCounter).Width = VB6.TwipsToPixelsX(LedWidth)
  Led(ledCounter).BorderStyle = Windows.Forms.BorderStyle.None
  Led(ledCounter).BackColor = System.Drawing.ColorTranslator.FromOle(LedColor)
  Led(ledCounter).Visible = True
Next

1 个答案:

答案 0 :(得分:3)

在VB6中,标签是windowless (lightweight) control。它没有窗口句柄,因此就操作系统而言不存在。此控件背后的代码只是检查鼠标的位置,并在父控件上进行绘制。

然而,在VB.NET中,标签是一个完整的控件,它有一个窗口句柄,因此“存在”。创建数千个这样做是个坏主意,因为number of available window handles is limited(因为它很慢)。

您应该修改设计并考虑使用某种网格。