vb.net 花费太多时间来加载包含标签控件数组的用户控件
我正在升级用户控件,从 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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 VB6 中,标签是一个 无窗口(轻量级)控件< /a>.它没有窗口句柄,因此就操作系统而言不存在。该控件背后的代码仅检查鼠标所在位置并在父控件上进行一些绘制。
然而,在 VB.NET 中,标签是一个成熟的控件,具有窗口句柄,因此“存在”。创建数千个这样的文件是一个坏主意,因为数量可用的窗口句柄是有限的(并且因为它很慢)。
您应该修改您的设计并考虑使用某种网格。
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.