Creating a dynamic flag at run time

Dim offset = 200
    For i = 0 To Form1.ListBox2.Items.Count - 1

        Dim cBox = New CheckBox()
        Me.Controls.Add(cBox)
        cBox.Location = New Point(80, offset)
        cBox.Text = Form1.ListBox2.Items.Item(i)
        offset = offset + 50
        ListBox1.Items.Add(Form1.ListBox2.Items.Item(i))

    Next i

I use this code to create a checkbox at runtime. The problem is how can I put the checkChanged event in these checkboxes. waiting for an answer. As soon as possible.

+3
source share
1 answer

You can use the command AddHandlerto register an event handler.

AddHandler cBox.checkChanged, AddressOf checkChangedHandler

Where checkChangedHandleris such a function:

Sub checkChangedHandler(sender As Object, e As EventArgs)
        Console.WriteLine("Check Changed")
End Sub 
+4
source

All Articles