Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cyclying through all controls in a form except pageframes

Status
Not open for further replies.

CFPR

MIS
May 9, 2003
58
0
0
PR
I'm almost done with a nice app that has about 50 forms. Now mgmt wants the forecolor property of all textboxes, combos, editboxes etc to be blue rather than black.

I could go one by one, but that over 1000 fields!!

I have the following code on a timer button
FOR x = 1 TO thisform.ControlCount
WITH thisform.controls(x)
IF INLIST (.CLASS,"Textbox","Combobox","Spinner","Checkbox","Editbox")
.FORECOLOR=RGB(0,0,255)
.disabledFORECOLOR=RGB(0,0,0)
ENDIF
ENDWITH
ENDFOR

I had to add the base class 'check' to ensure that the property had the forecolor,disabledbforecolor properties.

Here is the problem. This will not work with pageframes as the form controlcount does not include the controls within the pageframe. Is there any way to address the pageframes controls directly or do I have to loop through each page in the pageframe and then referecing each control to update the properties? Any code suggestions?

Thanks

MW
 
Mwilliams123

Here is a portion of the code from the SetAllProps method in the txtbtns (from the WizBtns class), the loops through the pages also and handling the controls on it, you might be able modify to work for you:
Code:
LPARAMETER oContainer

* Checks for General fields
LOCAL i,oControlParent,nCtrlCount

IF PARAMETERS() = 0
	m.oControlParent = THISFORM
ELSE
	m.oControlParent = m.oContainer
ENDIF

DO CASE 
CASE ATC("Pageframe",m.oControlParent.BaseClass)#0
	nCtrlCount = oControlParent.PageCount
CASE ATC(m.oControlParent.BaseClass,"Optiongroup,Commandgroup")#0
	nCtrlCount = oControlParent.ButtonCount
OTHERWISE
	nCtrlCount = oControlParent.ControlCount
ENDCASE

FOR i = 1 TO m.nCtrlCount 
	DO CASE
	CASE ATC("Pageframe",m.oControlParent.BaseClass)#0
		THIS.SetAllProp(m.oControlParent.Pages[m.i])
		
	CASE ATC(m.oControlParent.BaseClass,"Optiongroup,Commandgroup")#0 AND ;
		THIS.UserControlMode
		m.oControlParent.Buttons[m.i].Enabled = THIS.EditMode

	CASE ATC(m.oControlParent.Controls[m.i].BaseClass,"Optiongroup,Commandgroup")#0 ;
		AND THIS.UserControlMode
		THIS.SetAllProp(m.oControlParent.Controls[m.i])

	CASE ATC("Container",m.oControlParent.Controls[m.i].BaseClass) # 0 OR; 
		ATC("Page",m.oControlParent.Controls[m.i].BaseClass) # 0
		THIS.SetAllProp(m.oControlParent.Controls[m.i])

	CASE ATC(m.oControlParent.Controls[m.i].BaseClass,"ListBox,ComboBox,Spinner") # 0 AND;
		THIS.UserControlMode
		m.oControlParent.Controls[m.i].Enabled = THIS.EditMode

	CASE ATC(m.oControlParent.Controls[m.i].BaseClass,"OleBoundControl") # 0
		m.oControlParent.Controls[m.i].Enabled = THIS.EditMode

	CASE ATC(m.oControlParent.Controls[m.i].BaseClass,"CheckBox,TextBox,EditBox") # 0
		m.oControlParent.Controls[m.i].ReadOnly = !THIS.EditMode

	CASE ATC(m.oControlParent.Controls[m.i].BaseClass,"Grid") # 0
		m.oControlParent.Controls[m.i].ReadOnly = !THIS.EditMode
	* This Deletemark setting may need to be disabled if you have a trigger
	* on your child table (Restrict Delete).
	*	m.oControlParent.Controls[m.i].DeleteMark = THIS.EditMode
		
	ENDCASE
ENDFOR

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi,
maybe I didnot understand your question well.
But didnot you subclass the controls ?
If so just a change in the Library would do all work for you though ?
-Bart
 
Try this:
Code:
FOR EACH nPage IN THIS.PAGES
   FOR nWhich = 1 TO nPage.CONTROLCOUNT
      WITH nPage.CONTROLS(nWhich)
         IF INLIST (.CLASS,"Textbox","Combobox","Spinner","Checkbox","Editbox")
            .FORECOLOR=RGB(0,0,255)
            .DISABLEDFORECOLOR=RGB(0,0,0)
         ENDIF
      ENDWITH
   NEXT
NEXT

Dave S.
[cheers]
 
Let me clarify a little.
Change the first line as follows, and put in the Init event of the form:

FOR EACH nPage IN ThisForm.Pageframe1.PAGES
FOR nWhich = 1 TO nPage.CONTROLCOUNT
WITH nPage.CONTROLS(nWhich)
IF INLIST (.CLASS,"Textbox","Combobox","Spinner","Checkbox","Editbox")
.FORECOLOR=RGB(0,0,255)
.DISABLEDFORECOLOR=RGB(0,0,0)
ENDIF
ENDWITH
NEXT
NEXT


Dave S.
[cheers]
 
MWilliams123

Another idea. How about SetAll() method.

cProp1 = 'ForeColor'
cProp2 = 'DisabledBackColor'
nFore = RGB(0,0,255)
nBack = RGB(0,0,0)

With ThisForm
.SetAll(cProp1, nFore, 'Textbox')
.SetAll(cProp2, nBack, 'Textbox')

.SetAll(cProp1, nFore, 'Combobox')
.SetAll(cProp2, nBack, 'Combobox')
EndWith


-- AirCon --
 
MWilliams123,

I wouldn't do it in the runtime code at all, if the forecolor blue is a permanent change then looping through everything is unnecessary and will hog some resources and slow things down. I would use the Visual Foxpro Transformer Application to change all the forecolor properties of those controls (classes). Run the following code from the VFP command window or a prg and then follow the directions I set out below it.

Code:
CREATE TABLE C:\Transcolor.dbf (Rule C(254))
INSERT INTO TRANSFORM(rule) VALUES ("forecolor  |  0,0,255  |    |  *.scx  |  ComboBox «")
INSERT INTO TRANSFORM(rule) VALUES ("forecolor  |  0,0,255  |    |  *.scx  |  TextBox «")
INSERT INTO TRANSFORM(rule) VALUES ("forecolor  |  0,0,255  |    |  *.scx  |  EditBox «")
USE
DO (HOME()+ "tools\transfrm\transfrm.app")

Now, on the FILES tab of the transformer add in the folder that contains your form files, or you can selectively add scx, vcx, or pjx files as needed. Then, go to the RULES tab and open that table we just created. Now go to the LOG tab and click on the TRANSFORM button (don't worry nothing will get changed until you uncheck the CREATE LOG ONLY checkbox there) you're just testing it right now. It should show you all the textboxes, editboxes and comboboxes that it is going to change once it completes the operation. Now, if you created subclasses you can use this too, but what's the point since you can just change your subclass forecolor and it effects all the controls, so my bet is that you used VFP Base classes. Anyway, feel free to add to the rule table we made for other classes you want to change the forecolor for, or you could add some records to change the backcolor as well. Then when you are ready uncheck the CREATE LOG ONLY checkbox and click the TRANSFORM button and it will permanently change all the controls just like you went into each and every form and changed it yourself. Hope this helps, and that I explained it clearly enough.

Slighthaze = NULL
 
MWilliams123,

Maybe I don't need to say this, but before you do the operations I posted above, make a backup of your forms just in case.

Slighthaze = NULL
 
wow, was my suggestion that bad? I think I killed the thread. LOL :)

Slighthaze = NULL
 
Hi Slighthaze. No, not at all! What I like about this forum, and most, is the diverse way of doing things. Yours opened up new possibilities for me! Thanks.

I did, however, end up using AirCon suggestion. Short and sweet. At the end of the day, its really my fault as I should have sub-classed all text box, combos, etc. Maybe on my next project....

Anyway, thanks to all for the support!

MW
 
(in a singing way)
Feelings..
Nothing more than feelings...
Trying to forget my....

You guys are ALL awesome!!

MW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top