The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
Looping through controls in a form.
Posted: 18 Jul 08 7:47 AM
|
I've been asked to modify the Accounts Details view in SLX (7.02) so that the background turns Red/Green based on the happiness of the account.
Changing the background colour of the form alone looks terrible with all the buttons and labels over the top of it, so i decided I should modify the labels to use the same BG colour aswell, the only problem is that there are a lot of them and more will be added over time. I dont want to have to be writing "lblAccount.color = wclSeaGreen" over and over again.
Using some info I found in one Ryans guides I was able to loop through all controls in the form. My problem however is that I have no idea how to identify labels from other controls. (Not every label has been prefixed with "lbl"). Is there an easy way to ID them?
for i = 0 to frmAccountDetail.ControlCount - 1 ???? if frmAccountDetail.Controls(i)."I WOULD LIKE TO SAY TYPE" = "Label" then frmAccountDetail.Controls(i).color = clColor end if next
If i stick in an "On error resume next" the for loop does work (less the control type test) and changes every control that can be changed to green, but I'm only after labels at the mo.
Any ideas guys?
|
|
|
| |
|
Re: Looping through controls in a form.
Posted: 18 Jul 08 10:01 AM
|
Nice one, thanks.
Now if I could just figure out how to stop the buttons looking like crap... BG Colour will go green but the 3d effect colours arent customizable. 
Cheers
Greg |
|
|
|
Re: Looping through controls in a form.
Posted: 18 Jul 08 10:19 AM
|
Hi Greg,
For a button you need to turn off the UseThemes: m_form.Controls(i).Color = Color m_form.Controls(i).UseThemes = False
Cheers,
Steve |
|
|
|
Re: Looping through controls in a form.
Posted: 18 Jul 08 10:24 AM
|
I've tried that, you still get a grey border around the button.
Also you cant change usethemes on the fly (unless I was doing it wrong).
I think I may resort to replacing the buttons with labels that have on click events.
Or giving up and just make the text box containing the Account name turn green/red.
Or even better: objSLXDB.ExecuteSQL "DROP ACCOUNT"#
Cheers |
|
|
|
Re: Looping through controls in a form.
Posted: 18 Jul 08 10:56 AM
|
Hi Greg,
The following should work for button the usethemes on the fly: If TypeName(frmAccountDetail.Controls(i)) = "Button" Then frmAccountDetail.Controls(i).UseThemes = False frmAccountDetail.Controls(i).Color = = clColor End If
Choice is yours on next steps!
Be aware that checkboxes also are a pain too - need to remove the text portion and change to a label so that the color will change...
Cheers,
Steve
|
|
|
|
Re: Looping through controls in a form.
Posted: 18 Jul 08 11:38 AM
|
You're right. Me being an idiot did it the same way as a boolean in the SLX DB (.usethemes = "F")
I think it's going to look messy, so I'm just going to change the BG of the Account textbox.
But the typename() will be very useful in the future. Thanks |
|
|
|
Re: Looping through controls in a form.
Posted: 19 Jul 08 2:33 AM
|
Greg, no matter what you do here - the ultimate form will look like crap ! The mix of colour, bevel, pane and so on just doesn't lend itself to be colorised liek this.
I'd suggest to alternatives - have a horizontal bar running complete width of the form and change the colour of this - and put some text in there too - e.g. "Great Customer!" - as this is enough to focus the eye and highlight - without getting seasick (as opposed to seagrape).
Or, put a web control on the right - and use HTML to create a nice looking "Status" panel.
Regards Mike
|
|
|
|
Re: Looping through controls in a form.
Posted: 22 Jul 08 7:58 AM
|
Indeed it did.
The higher-ups agreed, and we've settled on changing the colour of the textbox that contains the account name. (We barely have space on the form for our current controls, let alone space to stick a green/red bar up the top)
Thanks a lot guys
Greg |
|
|
|
Re: Looping through controls in a form.
Posted: 22 Jul 08 8:20 AM
|
Thought so ! I get asked for this a lot - and always turn it down as a bad idea. Also, have you thought about a tab control in the main views? You can separate data into the tabs - most important at the front and others for other data. This is a tabcontrol on the mv - not a tab in the tabset. Worth considering if you have a lot of fields. |
|
|
|
Re: Looping through controls in a form.
Posted: 06 Aug 08 6:21 PM
|
Hi,
I've stumbled across this bit of code and realised how much easier it would make life, but I'm having some difficulty getting it working!
All I am trying to do is enable / disable controls on a panel, so I have used the following (to enable the fields):
For i = 0 to pnl_Printer.ControlCount - 1 pnl_Printer.Controls(i).Enabled = True Next
But it does not work, I get an error when the code is called.
Any ideas, or can this only be used for forms rather than for panels?
|
|
|
| |
|
Re: Looping through controls in a form.
Posted: 07 Aug 08 3:22 AM
|
I will now hang my head and sulk in the corner.
Why do I always look for the difficult way to do things!!??!!
Thanks for pushing me in the right direction! |
|
|
| |
|
Re: Looping through controls in a form.
Posted: 07 Aug 08 7:19 AM
|
Mike,
Yes I've had a look at that, and I have tried to implement it and come across errors. Basically I have a form with (literally) hundreds of controls on it, some on the form but the majority are on 1 of 6 panles which I set Visible as required (the panels are on top of each other).
I have three panels which are visible at the same time, but I only want the controls on one to be enabled at a time.
I would really like to use this code as it is by far the simplest solution, but It would be very difficult to identify which controls should be enabled and which disabled using the TypeName. Is there any way of using the 'Name' of the control - I have been very strict as to the naming convention, so I can guarantee that doing it this way would ensure the correct controls would be disabled.
For example: "If Left(Name(Controls(i)), 3) <> "ABC" Then Controls(i).Enabled = False" would do exactly what I wanted, but the Name property does not return the name of the control?
Regards, Paul.
|
|
|
|
Re: Looping through controls in a form.
Posted: 07 Aug 08 7:24 AM
|
Yup, you can:
============================ Dynamic Objects/VariableName ============================
> For T = 1 to 58 > Execute "MyControl" & T & ".Enabled = True" > Next
So, if they are numbered sequentially (or you use an array/whatever) - you can do that.
Mike
|
|
|
|
Re: Looping through controls in a form.
Posted: 07 Aug 08 7:38 AM
|
Although I can see the benefit, due to my naming convention this would still be fairly messy.
I have named the controls PanleName_Label_01, PanelName_Text_01, etc. so I'd have to do a seperate loop for each type of control, and for each panel!
If there is a way of using the TypeName(Controls(i)) but to get the neam of the control rather than the Type it would be 3-4 lines of code.
I may be expecting too much, but woudl NameName(Controls(i)) work??? I'm going to try...
...No, that didn't work!
|
|
|
| |
|
Re: Looping through controls in a form.
Posted: 07 Aug 08 10:25 AM
|
Steve,
You really are coming to my aid today!
yes, this has done the trick.
Looking at the code, the fact that I had "Controls(i).Enabled = False", I should have really guessed that I could reference "Controls(i).Name".
I'm reminded of a phrase regarding wood & trees.
Thanks again. Paul. |
|
|
| |
|
Re: Looping through controls in a form.
Posted: 07 Aug 08 11:23 PM
|
Hi Paul,
Optionally, you could so something like add a value in the tag property of the controls you want to disable. So in the loop you only set it as enabled=false if the tag value equals something like "1". Then just add the "1" in the controls you want to disable (or do it the other way around by flagging the ones you want left alone. This way you don't need to hard code all the control names.
-Ryan |
|
|
|
Re: Looping through controls in a form.
Posted: 08 Aug 08 3:01 AM
|
Ryan,
Thanks for the hint. In this situation I have six panels,a dn the user is able to switch between them, so I'd have to have each one with a different number in the Tag, an to be honest if anybody else does any development, getting them to remember to do this would be more difficult than getting them to remember to name the controls correctly!
Thanks all the same, I may well use this elsewhere. Paul. |
|
|
|