vb.net taking too much time to load user control containing Label control array

ε祈祈猫儿з 提交于 2019-12-24 18:03:14

问题


I am upgrading user control from vb6 to vb.net.
In the vb6 application I am loading 3000 labels using a label control array.
In vb.net I am doing same but it's taking too much time to load.
In vb6 it's taking 1-2 seconds, but in vb.net it's taking 30-40 seconds for same work.
What is problem? Why does it take too much time in vb.net for same work?

Code is given below, here Led is the label control array.

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:


In VB6, a label is a windowless (lightweight) control. It doesn't have a window handle and therefore does not exist as far as the OS is concerned. The code behind this control just checks where the mouse is and does some drawing on the parent control.

In VB.NET, however, a label is a full-fledged control that has a window handle and therefore "exists." Creating several thousands of these is a bad idea, because number of available window handles is limited (and because it's slow).

You should revise your design and consider using a grid of some sort.



来源:https://stackoverflow.com/questions/8601700/vb-net-taking-too-much-time-to-load-user-control-containing-label-control-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!