Information générale
Catégorie:
Codage, syntaxe et commandes
"How can I check whether a specific property exists for a control? I want to change the forecolor of all the controls wherever possible. For that, I need to check whether forcolor property exists for each control."
Hi Yashodhan,
Here is an example method of how you can loop through all controls on a form or container and check for the forecolor property and change it. This is just an example to get you started. Essentially, you want to recursively loop through all containers, and when you find a textbox or edit box, you can change it to the passed color.
*-- Example Method SetAllForeColor
*-- Attach this method to a form.
*-- Loop through all objects on a form looking for text or edit objects
*-- Pass in the topmost object you want to start checking. i.e. THISFORM
*-- If you want this method to ignore the passed object add a property called
*-- lIgnore. This method will ignore objects with the lIgnore property
LPARAMETER oContainer, lnColor
LOCAL I, oControl, lUsePages, lUseGroup, oObject
LOCAL lnControlCount
IF PCOUNT() < 2
lnColor = RGB(0,0,128) && Whatever
ENDIF
IF PCOUNT() = 0 && If you don't pass in an object, assume thisform
oControl = ThisForm
ELSE
oControl = oContainer
ENDIF
lUsePages = .F.
lUseGroup = .F.
DO CASE
CASE UPPER(oControl.BaseClass) = "PAGEFRAME"
lnControlCount = oControl.PageCount
lUsePages = .T.
CASE UPPER(oControl.BaseClass) = "COMMANDGROUP"
lnControlCount = oControl.ButtonCount
lUseGroup = .T.
OTHERWISE
lnControlCount = oControl.ControlCount
ENDCASE
FOR I = 1 TO lnControlCount
DO CASE
CASE lUsePages && Page Frames
oObject = oControl.Pages(i)
CASE lUseGroup && Option Group and Command Group
oObject = oControl.Buttons(I)
OTHERWISE
* Default
oObject = oControl.Controls(I)
ENDCASE
DO CASE
CASE TYPE("oObject.lIgnore") = "L" AND oObject.lIgnore
*-- If you want to ignore a particular object
*-- add lIgnore property L and test here
CASE ATC("Page",oObject.BaseClass) # 0
This.SetAllForeColor(oObject)
CASE ATC("Container",oObject.BaseClass) # 0
This.SetAllForeColor(oObject)
CASE ATC("CommandGroup",oObject.BaseClass) # 0
This.SetAllForeColor(oObject)
CASE ATC( "TextBox",oObject.BaseClass") # 0
AND TYPE("oObject.ForeColor") ="N"
*-- Set the color the way you want
oObject.ForeColor = lnColor
CASE ATC(oObject.BaseClass,"EditBox") # 0
oObject.ForeColor = lnColor
ENDCASE
ENDFOR
I hope this helps.
Bob
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement