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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

with thisform to change dynamic forecolor

Status
Not open for further replies.

fxsage

Programmer
Sep 9, 2002
21
US
I need to apply: THISFORM.command1.FORECOLOR=RGB(255,0,0)
to all of the option click events in an option group.
I don't have the correct syntax for the 'with thisform.optiongroup1' et cet. Would appreciate the syntax for this statement.

Thanks
 
There is no ForeColor property on the OptionGroup - only on the individual Options. Try:
Code:
THISFORM.Optiongroup1.Option1.FORECOLOR=RGB(255,0,0)
THISFORM.Optiongroup1.Option2.FORECOLOR=RGB(255,0,0)
THISFORM.Optiongroup1.Option3.FORECOLOR=RGB(255,0,0)
Rick




 
Put the following into the InterActiveChange event of the optiongroup:

this.SetAll("ForeColor",0,"OptionButton")
this.Buttons(this.Value).forecolor = 255


...here is a working example of it (cut-n-paste into a prg and run from within VFP):

PUBLIC oForm
oForm = CREATEOBJECT("form1")
oForm.show()
DEFINE CLASS form1 AS form

Top = 0
Left = 0
Height = 191
Width = 132
DoCreate = .T.
Caption = "Form1"
Name = "Form1"
AutoCenter = .T.

ADD OBJECT optiongroup1 AS optiongroup WITH ;
ButtonCount = 6, ;
Value = 1, ;
Height = 132, ;
Left = 24, ;
Top = 24, ;
Width = 84, ;
Name = "Optiongroup1", ;
Option1.Caption = "Option1", ;
Option1.Value = 1, ;
Option1.Height = 17, ;
Option1.Left = 5, ;
Option1.Top = 5, ;
Option1.Width = 61, ;
Option1.ForeColor = RGB(255,0,0), ;
Option1.Name = "Option1", ;
Option2.Caption = "Option2", ;
Option2.Height = 17, ;
Option2.Left = 5, ;
Option2.Top = 24, ;
Option2.Width = 61, ;
Option2.Name = "Option2", ;
Option3.Caption = "Option3", ;
Option3.Height = 17, ;
Option3.Left = 5, ;
Option3.Top = 43, ;
Option3.Width = 61, ;
Option3.Name = "Option3", ;
Option4.Caption = "Option4", ;
Option4.Height = 17, ;
Option4.Left = 5, ;
Option4.Top = 62, ;
Option4.Width = 61, ;
Option4.Name = "Option4", ;
Option5.Caption = "Option5", ;
Option5.Height = 17, ;
Option5.Left = 5, ;
Option5.Top = 81, ;
Option5.Width = 61, ;
Option5.Name = "Option5", ;
Option6.Caption = "Option6", ;
Option6.Height = 17, ;
Option6.Left = 5, ;
Option6.Top = 100, ;
Option6.Width = 61, ;
Option6.Name = "Option6"

PROCEDURE optiongroup1.InteractiveChange
this.SetAll("ForeColor",0,"OptionButton")
this.Buttons(this.Value).forecolor = 255
ENDPROC

ENDDEFINE


Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
fxsage

It's more efficient to address an object once and change 3 properties rather than address an object 3 times and change 1 property.

So you can use the alternative code :-

WITH THISFORM.Optiongroup1
[tab].Option1.FORECOLOR=RGB(255,0,0)
[tab].Option2.FORECOLOR=RGB(255,0,0)
[tab].Option3.FORECOLOR=RGB(255,0,0)
ENDW



FAQ184-2483 - answering getting answered.​
Chris [pc2]
 
I need to clarify...I want to change the forecolor of a command button, based on the clicks in an optiongroup.

Thanks again
 
Ok, here is an example of how to do that:

PUBLIC oForm
oForm = CREATEOBJECT("form1")
oForm.show()

DEFINE CLASS form1 AS form
Top = 0
Left = 0
Height = 191
Width = 132
DoCreate = .T.
Caption = "Form1"
Name = "Form1"
AutoCenter = .T.
ADD OBJECT optiongroup1 AS optiongroup WITH ;
ButtonCount = 3, ;
Value = 1, ;
Height = 72, ;
Left = 24, ;
Top = 24, ;
Width = 84, ;
Name = "Optiongroup1", ;
Option1.Caption = "Option1", ;
Option1.Value = 1, ;
Option1.Height = 17, ;
Option1.Left = 5, ;
Option1.Top = 5, ;
Option1.Width = 61, ;
Option1.Name = "Option1", ;
Option2.Caption = "Option2", ;
Option2.Height = 17, ;
Option2.Left = 5, ;
Option2.Top = 24, ;
Option2.Width = 61, ;
Option2.Name = "Option2", ;
Option3.Caption = "Option3", ;
Option3.Height = 17, ;
Option3.Left = 5, ;
Option3.Top = 43, ;
Option3.Width = 61, ;
Option3.Name = "Option3"
ADD OBJECT command1 AS commandbutton WITH ;
Top = 120, ;
Left = 24, ;
Height = 27, ;
Width = 84, ;
Caption = "Command1", ;
Name = "Command1"
PROCEDURE optiongroup1.InteractiveChange
LOCAL lnValue
lnValue = this.Value
DO case
CASE lnValue = 1
thisform.command1.ForeColor = 255
CASE lnValue = 2
thisform.command1.ForeColor = 65280
CASE lnValue = 3
thisform.command1.ForeColor = 16711680
ENDCASE
ENDPROC
ENDDEFINE



Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
You don't need to trap the CLICK events of the individual option buttons. Just put your statement

THISFORM.command1.FORECOLOR=RGB(255,0,0)

in the CLICK event of the optiongroup.

Jim
 
fxsage,

Is there a specific reason that the solutions provided so far have not solved your problem? Is there something additionally that you are trying to do? If so, perhaps you could post the code you have tried yourself and exactly what it is you are trying to do, then we could provide you additional help if needed. Another thing you may find useful is to set a break point in your code and watch it execute line by line in the debugger...this may give you a better understanding of how click events work and what the behavior is for contained controls and the container.

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
no; it's just that I need to change the forecolor of a command button, based on clicks in an optiongroup. I'm not trying to cgange the color of any option groups.

Rather than repeat the same line of code in each of the 18 option groups, I wanted a global code that would change the command button forecolor regardless of which option group I click on.

Thanks
 
Just to clarify, do you have 18 optiongroups or 1 optiongroup with 18 buttons? -Jim
 
Then the answer I gave previously will work. The optiongroup itself has its own click event which will fire whenever one of its buttons is clicked. so just place your statement

THISFORM.command1.FORECOLOR=RGB(255,0,0)

in the click event of the optiongroup.

Jim
 
That was the first thing I tried. However, you have to click outside the option groups for this to work. I need my users to click on the specific options they require. Doing this doesn't affect the command button. That's why I thought there must be a way around placing that liitle command line in 18 different option groups.
 
I've tried this in 5.0 and 7.0 and can't reproduce the behavior you describe. When I click directly on an individual button the optiongroup click event fires. I don't need to click "outside."

Jim

 
Yeah, it seemed strange to me too. This particular app is also in 5.0. Maybe there is an optiongroup property I don't have selected.
 
As a possible workaround you can try the Interactivechange event rather than the Click.

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top