I have a ComboBox (motionComboBox) with values: STOP, GO, PAUSE
I have a label for the box (labelmotionComboBox).
I want to change the Foreground.Color of both of these items depending on which value the user selects from the combo box.
I have tried various combinations that will compile clean, but halts the program when I change the value.
Surely this can be done, but as usual I have run out of insight.
ALL thoughts would be gratefully appreciated.
Loading
Sam HobbsPosted Apr 18, 2010, 1:56 PM
Rick ClemonsPosted Apr 18, 2010, 11:24 AM
It really is as simple as it should be.
This works:
if (comboBoxTrafficStatus.SelectedItem.ToString() == "RED")
{
labelTrafficStatus.ForeColor = System.Drawing.Color.Red;
comboBoxTrafficStatus.ForeColor = System.Drawing.Color.Red;
}
Thanks again.
Rick ClemonsPosted Apr 18, 2010, 10:28 AM
Colloquialism: A characteristic of or appropriate to ordinary or familiar conversation rather than formal speech or writing;
BARF means to vomit or retch. It is an onomatopoeic word accepted in common usage since 1960.
As used in my note, it means that the program comes to an abrupt halt and spews forth (vomits / retches) a distasteful expectorate; an error message.
I have disabled the code for the moment so that I can move forward with this project that needs to get done and will come back to it if I have time.
I do appreciate your help and if you have any insight as to how to accomplish the function.
Thanks for working on this seemingly simple function that has me baffled.
Sam HobbsPosted Apr 18, 2010, 2:55 AM
Rick ClemonsPosted Apr 17, 2010, 10:41 PM
When the program starts up all is well; the color is set according to the value in the comboBox.
The value is coming from an XML file:
The code below will set the comboBoxFlowStatus.ForeColor appropriately.
HOWEVER COMMA...
When the status change event occurs...Barf!
{
if (comboBoxFlowStatus.SelectedItem.ToString() == "RED")
{
this.comboBoxFlowStatus.ForeColor = System.Drawing.Color.Red;
labelFlowStatus.ForeColor = Color.Red;
}
}
Sam HobbsPosted Apr 17, 2010, 9:19 PM
So the following might help, but I have left a lot for you to do and I am not sure if this will do what you need even if you do the rest.
First add "using System.Runtime.InteropServices;" to the top of the program. Then add the following as members of the form class.
Then I think the following will get the handle of the edit control. Note that you will need to do the code to set the color, which might be more work than you want to do, but whatever you do, I think you must do it in a handler of either a WM_CTLCOLOREDIT or a WM_CTLCOLORSTATIC message sent to the form. Also this probably will not work for a DropDownList style.