How add button programmatically in RadioButton?

In the previous article you saw how customize classic radio button to have a flat button with two state.

I want create an horizontal menu bar, but it’s no easy like the list box add an item, in this case item is a button. 

Now we want know how add a button programmatically.

Vi scripting help us to do this.

First step enable vi scripting.

With script code you can do this:

Move method, has a duplicate option that create a copy of the control.

This work only in edit mode, than it’s not usable to create my menu at runtime. It’s true that’s I need to know the item before to create action for each item. But figure out you want create dynamic menu, you can use this solution.

You can use it to create quickly other button in the radio with the same flat style of the last button you’re created.

Code to copy last button

Now if you using subpanel, the menu is in a separated Vi, then before you run this you can use the move method to configure you’re menu. A simple trick is to abort and after update the menu, run the Vi.

In the sample each times “Update Menu” is pushed a button is added .

Now creating an array of string that changes the boolean text you have something like the list box menu but button based and with horizontal or vertical arrangement autosizing.

However is not completely useful add a button at run time if you don’t have piece of code that do something for new button created. I use this to create a menu from template, and with some creativity you could use the caption string or boolean text to prepare the code need in case you create this buttons, in example.

About the Move Object Method that inspire me, see this Tutorial.


Nicola Bavarone