Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

Buttons, ButtonCount

Let me take you a button-hole lower.
—William Shakespeare, Love’s Labour’s Lost

These properties tell you about the buttons in a button group, whether they’re option buttons or command buttons. ButtonCount tells you how many are in the group, while Buttons gives you access to the PEMs of the individual buttons.

Usage

oObject.ButtonCount = nNumberOfButtons
nNumberOfButtons = oObject.ButtonCount
oButton = oObject.Buttons( nButtonNumber )

You can change the number of buttons in a group by changing ButtonCount. If you lower ButtonCount, any extra buttons disappear into oblivion.

The Buttons collection lets you get at the individual buttons within a button group without worrying about their names. You can look up or change properties or invoke buttons’ methods by accessing the button through Buttons.

To change properties of all the buttons in a group, use the button group’s SetAll method instead.

Example

* Look for the button whose caption is "My Favorite Button"
* Assume we're in a method of the button group
LOCAL nButton, lFoundIt
nButton = 1
lFoundIt = .F.
DO WHILE nButton <= This.ButtonCount AND NOT lFoundIt
   IF This.Buttons[nButton].Caption = "My Favorite Button"
      lFoundIt = .T.
   ELSE
      nButton = nButton + 1
   ENDIF
ENDDO
IF lFoundIt
   WAIT WINDOW "My Favorite Button is "+LTRIM(STR(nButton))
ELSE
   WAIT WINDOW "My Favorite Button is missing"
ENDIF

See Also

ControlCount, Controls, SetAll