Can you dynamically create buttons?

trend

Centurion
Joined
Oct 12, 2004
Messages
171
Hello, I am looking to populate a form with buttons based on the results from a db query..

So lets say, the db query returns: Red, Green, Blue, Purple
I would want vb to create 4 buttons, space them 20 pixels appart, and make the name of the button to correspond to the db query.

So the result would be :

(Red) (Green)(Blue)
(Purple)

(the form only has room for 3 button wide).


thanks for any pointers!
Lee
 
Last edited:
i wish I could delete posts.. because there was a post with the identical name to this one that had the answer :/

Code:
        Dim btn As New Button

        With btn
            .Size = New Size(90, 40)
            .Location = New Point(15, 15)
            .Text = "Testing 1 2 3"

            'causes the newbtnClick procedure to fire on the click event.
            AddHandler btn.Click, AddressOf newbtnClick
        End With

        Me.Controls.Add(btn)
 
Back
Top