Board index » cppbuilder » Setting Font Color of TComboBox

Setting Font Color of TComboBox

If I programmatically set the color of a combo box, the text within the
combo box control gets marked as selected even though it is not the
currently active control and does not have focus.  If I click in the
combo box to unselect the text value, the colour is what I have changed
it to.  Why does the text get marked as selected when the colour is
changed?  Can I avoid this behaviour without having to take over the
drawing of the combo box?

Thanks in advance

Sean Hannan

 

Re:Setting Font Color of TComboBox


Quote
Sean Hannan wrote:

> If I programmatically set the color of a combo box, the text within the
> combo box control gets marked as selected even though it is not the
> currently active control and does not have focus.  If I click in the
> combo box to unselect the text value, the colour is what I have changed
> it to.  Why does the text get marked as selected when the colour is
> changed?  Can I avoid this behaviour without having to take over the
> drawing of the combo box?

The following button handler does not do this, so it must be in your code.

void __fastcall TForm1::Button1Click(TObject *Sender) {
   ComboBox1->Font->Color = clGreen;
   ComboBox1->Color = clYellow;

Quote
}

(After clicking the button, the button has taken the focus away from the box,
and the box is the above colors.)

David

Re:Setting Font Color of TComboBox


In article <3BF516C4.43B3C804@anonymous_one.com>, david@anonymous_one.com
says...

Quote
> Sean Hannan wrote:

> > If I programmatically set the color of a combo box, the text within the
> > combo box control gets marked as selected even though it is not the
> > currently active control and does not have focus.  If I click in the
> > combo box to unselect the text value, the colour is what I have changed
> > it to.  Why does the text get marked as selected when the colour is
> > changed?  Can I avoid this behaviour without having to take over the
> > drawing of the combo box?

> The following button handler does not do this, so it must be in your code.

> void __fastcall TForm1::Button1Click(TObject *Sender) {
>    ComboBox1->Font->Color = clGreen;
>    ComboBox1->Color = clYellow;
> }

> (After clicking the button, the button has taken the focus away from the box,
> and the box is the above colors.)

> David

David,

I don't think it is my code.  I tried a few things and put in the
following button handler and it still does the same thing (where
ProtectionRating is the name of the combobox.

void __fastcall TFrameCableDetails::Button1Click(TObject *Sender)
{
  ProtectionRating->Font->Color = clBlue;  

Quote
}

I then changed the combo box from csDropDownList to csDropDown and the
text did not get selected so the problem appears only to be when the
style is set to csDropDown.

Does anyone know if this is a component bug or if I should just be
setting the font colour some other way?

Regards

Sean Hannan

Other Threads