Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I try to add button into vb programatically
but my button did not load in the form..

can i know what is my problem?

What I have tried:

VB
Dim _button() As Button
Dim _x As Integer = 20
Dim _y() As Integer = {0, 50, 100, 150, 200, 250, 300, 350, 400, 450}

For i As Integer = 1 To 10
    ReDim _button(i)
    With _button(i)
        .Visible = 1
        .Text = i
        .Size = New Size(20, 50)
        .Location = New Point(_x, _y(i - 1))

        Controls.Add(_button(i))

    End With
Next
Posted
Updated 18-May-16 2:48am
v2

1 solution

You don't create an object!
Try it like this:
VB
Dim _button() As Button
Dim _x As Integer = 20
Dim _y() As Integer = {0, 50, 100, 150, 200, 250, 300, 350, 400, 450}
 
For i As Integer = 1 To 10
  _button = New Button
  ' and so long
 
Share this answer
 
Comments
newbie1992 18-May-16 8:57am    
thank you
Leo Chapiro 18-May-16 9:06am    
You are welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900