Can I add a command button in a form at run time?

dkons
06-01-2005, 06:49 AM
I want to make it possible for the user of my interface to add command buttons in the form through a menu command and after pointing by mouseclicking where he wants the cb to be placed each time.

If you have any idea of how can I do this, please help.... ;)

Thanks in advance
dkons

Iceplug
06-01-2005, 07:01 AM
I'd recommend using a control array. If you haven't worked with one:

You add a command button to the form.
Set the name of the command button to something and then set the index property. You now have a control array with one element.
To add another at design time, click it, press Copy, and then press Paste.

Don't forget to add code to it. Notice, in the event handler, you get an extra Index argument.

To add another command button at run time, you can do this:
Load yourcommandbuttonname(1)
it works the first time, but fails the second time because index 1 will already exist, so you need to change the index based on the number of command buttons you have already.

X = yourcommandbuttonname.UBound + 1
Load yourcommandbuttonname(X)
'At this point, the newly created button is invisible and underneath the last one.
yourcommandbuttonname(X).Move 50, 112
yourcommandbuttonname(X).Visible = True
'Now you should have a command button.

The command button's events are handled by the event procedures that you have set for the first one. :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum