[Gambas-user] Setting properties in a group

richard terry rterry at ...1946...
Sat Feb 21 03:44:39 CET 2009


On Fri, 20 Feb 2009 03:15:25 pm Anuradha Ratnaweera wrote:
> Hi all,
>
> I have several buttons on a form, generated using the GUI, not though
> code.  Say their names are "Button1", "Button2" etc - a lot of them.
>
> First, I wanted to share an event handler for all the buttons.  I did
> this putting them all to a group called "Buttons" and using the event
> handler "Buttons_Click".
>
> Now I need to set the properties of all the buttons in the group.
> E.g.: to disable / enable them.  Is there a way to iterate over all
> the buttons belonging to the group "Buttons"?
>
> Thanks in advance.
>
>         Anuradha

This will do what you want, and is what Benoit was referring to about 
iterating:

In this example I've put a VerticalBox on a form and put some buttons inside 
it . When  you call this from code it will enable or disable the buttons: I 
quickly made up a little project to make sure this works which it does.

eg. Toggle_Buttons(False) will disable them all at once


Public Sub Toggle_Buttons(aflag as boolean)
     Dim hCtrl As control
     Dim aButton As Button
     For Each hctrl In Vbox1.Children
	     If hctrl Is button Then
        	    aButton = hctrl
            	    aButton.enabled = aFlag
            End If
    Next
End

If you are coming from visual basic, you've probably been used to addressing 
them as a control array eg button(1), button(2) and being able do do a loop 
through them to enable, disable.

Gambas is stunningly better than visual basic, you will get used to it if you 
persist and see its merits

keep sending us questions as you need to.


Regards

Richard





More information about the User mailing list