Controls, ControlCount
These properties let you access all the controls in a container without knowing what they are. ControlCount tells you how many there are, while Controls is an array where each element contains a reference to one control. Controls is also referred to as a collection. (Other collections in Visual FoxPro include Forms and Pages.)
Usage |
nControls = oObject.ControlCount oControl = oObject.Controls( nControlNumber ) oObject.Controls( nControlNumber ).Property = uPropertyValue uPropertyValue = oObject.Controls( nControlNumber ).Property oObject.Controls( nControlNumber ).Method() |
Example |
* In VFP 5 and later, FOR EACH can be used to loop * through the collection. This avoids the need for the * nCounter variable and means you don't need to check * ControlCount. LOCAL nCounter FOR nCounter = 1 TO ThisForm.ControlCount * Make sure the property you're interested in exists before * changing it. IF TYPE("ThisForm.Controls[nCounter].BackColor") = "N" ThisForm.Controls[nCounter].BackColor = RGB(255,0,0) ENDIF * If it's an option button group, dig down and do the * contained buttons, too. IF UPPER(ThisForm.Controls[nCounter].BaseClass) = ; "OPTIONGROUP" ThisForm.Controls[nCounter].SetAll("BackColor", ; RGB(255,0,0)) ENDIF ENDFOR * SetAll does everything above and more. ThisForm.SetAll("BackColor", RGB(255,0,0)) |
See Also |
ButtonCount, Buttons, ColumnCount, Columns, FormCount, Forms, Objects, PageCount, Pages, SetAll |