问题
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