Hey guys,

I want to write code that does something like this:

If option = 1 Then
Create one Button and display it
Else If option = 2 Then
Create two Buttons and display them
End If


To do this, can I simply do:

If option = 1 Then
     Dim Button1 as Button
     Me.Button1.Show()
End If

And on like that?

Thanks,
JP

Recommended Answers

All 3 Replies

Unless you're willing to use Windows API calls, VB doesn't really do dynamic control creation very well. Partly this is because of the whole event procedure registration thing, callback function stuff and the like.

As a workaround, you can create the necessary buttons at design time, but make them Visible = False. Then, when you evaluate your Option variable as above (whatever it is) you can selectively unhide the buttons you've created.

Hope this helps!

I don't understand what you want? You want to create a button or show a button? so more details.................

Just like what BitBit said, try to create a button during design time and make it visible = false in the property window.

When u need it, u can unhide it or make it visible like this:

Command1.visible = true
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.