0

I am creating some buttons dynamically in vb.net, but i am not able to create the click event handler.

This is my code:

dim b(10) 
dim x=0
b(x) = New Button
b(x).width = 100
b(x).height = 25
b(x).location = New Point(500, pos + 24)
b(x).visible = True
b(x).text = "Remove"

AddHandler b(x).Click, AddressOf remove_click

I am getting the following error when i try to compile 'Click' is not an event of 'Object'.

Public Sub remove_click(sender As Object, e As EventArgs)
' onclick code
End Sub

2 Answers 2

2

The problem is that you never provided a type for the local b hence it's defined as an array of Object. The type Object has no Click event hence AddHandler fails. You need to declare this as an array of Button values

dim b(10) as Button
Sign up to request clarification or add additional context in comments.

Comments

0

You should always assume the compiler is right, and then try to discover what that implies. It says 'Click' isn't an event of 'Object', so you must be referencing object.Click, which implies that b(x) is an object, which implies that b is an array of object.

You thought it was an array of Button.

So,

Dim b(10) As Button

Comments

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.