4
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'm using this code to create a checkbox during runtime.. problem is how can I put checkChanged event in these checkboxes. looking forward for an answer. ASAP.

1 Answer 1

5

You can use AddHandler command to register an event handler.

AddHandler cBox.checkChanged, AddressOf checkChangedHandler

Where checkChangedHandler is a function like this:

Sub checkChangedHandler(sender As Object, e As EventArgs)
        Console.WriteLine("Check Changed")
End Sub 
Sign up to request clarification or add additional context in comments.

3 Comments

@killd... yes similar code can be used for any Control of Windows Forms.
thank you, please help me with this stackoverflow.com/questions/21966527/…
i already used and tried your given code.. thank you for that. :) i just use other code because my teacher requested so... I'm sorry for misunderstanding..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.