vb.net LED BOARD DISPLAY user control

2019-09-21 06:05发布

问题:

I am developing LEDBOARD user control in vb.net.I have done it also .Actually its taking too much time to load .In the vb6 same application I am loading 3000 labels using a label control array but not time consuming .In vb.net I am doing same but it's taking too much time to load 3000 labels.Is there any other way(any control or any custom control) to draw input text(any font style),image like below image It looks like below

回答1:

Create your LedBoard control from scratch by inheriting from Control, instead of using a UserControl and adding tons of labels.

I just made a little test to show you what I mean. You will have to adapt the logic to meet your needs.

Public Class LedBoard
    Inherits Control

    Private _rand As Random = New Random()

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        e.Graphics.FillRectangle(Brushes.Black, 0, 0, Width, Height)

        Const nx As Integer = 40, ny As Integer = 25

        Dim w = CInt((Width - 1) / nx) - 1
        Dim h = CInt((Height - 1) / ny) - 1
        For x As Integer = 0 To nx - 1
            For y As Integer = 0 To ny - 1
                If _rand.NextDouble() < 0.8 Then
                    e.Graphics.FillRectangle(Brushes.Red, x * (w + 1) + 1, y * (h + 1) + 1, w, h)
                End If
            Next
        Next

    End Sub

End Class