• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 500
  • Last Modified:

How to eliminate the blue background from a disabled combobox

Hello,
I have a form with several controls, including a combobox. The formcreate calls a procedure to fill the edits, which are left as not enabled until an Edit button is pressed. My problem is that the combobox is set to the ItemIndex = 0, and then a blue background is shown on it instead of the DisabledColor. The combobox is not enabled, but it shows the referred background. How can I have it show the default value but keep the defined DisabledColor? I also have this problem in certain TEdits, where the blue background is shown partially on the TEdit box.
Thank you.
0
hcarvajal
Asked:
hcarvajal
  • 6
  • 6
  • 2
  • +4
3 Solutions
 
shaneholmesCommented:
As mokule usually states....

Place a TPanel underneath the TComboBox, and set the panel 's enabled property = false instead of TComboBox

then set the color of TComboBox as you like  


 Panel1.Enabled:= False;
 ComboBox1.Color:= clBtnFace;


 Panel1.Enabled:= True;
 ComboBox1.Color:= clWindow;


Shane
0
 
hcarvajalAuthor Commented:
Thanks. Disabling the panel works fine, but I am still getting the blue background behind the text corresponding to the ItemIndex. For example, my first entry in the Items for the combobox is Weekly. If the panel is disabled, the combobox is disabled, but I get a blue color under Weekly and on the rest of the combobox I get the color set with ComboBox1.Color := xxxx.
My initialization code does the following:

 if TmpStr = 'W' then ComboBox1.ItemIndex := 0 else
   if TmpStr = 'B' then ComboBox1.ItemIndex := 1;

Thank you.
0
 
shaneholmesCommented:
huh, if its disabled, how could you possibley get a blue color background.

"but I get a blue color under Weekly and on the rest of the combobox I get the color set with ComboBox1.Color := xxxx. "

How can this be possible, if its disbaled? You have no access t those items.

Shane

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
shaneholmesCommented:
Is your project big, maybe something you can zip and send me - so i can see

Shane
0
 
hcarvajalAuthor Commented:
It is disabled, but I believe that the initialization has something to do with it. The project is big, and is connecting to a database to obtain the default values.
Thanks
0
 
Slick812Commented:
hello hcarvajal, I am not certain about the "Blue Color" that you talk about? ?, However in a combo box, the edit is either the "Windows" color or the "DisAbled" color (Button color), the only other color that I have seen is the "Selected Text" color, so I guess this is what is in the combo?

if it is the selected text color then you might try

ComboBox1.ItemIndex := 0;
ComboBox1.SelLength := 0;  // set NO selected text
0
 
shaneholmesCommented:
Is this a ComboBox or a DBComboBox?

Shane
0
 
hcarvajalAuthor Commented:
Hello,
The background color is the Selected Text color. It is a ComboBox.  I tried theh SelLength := 0, but it does not changes the situation. I have to enable the ComboBox and then click on it to remove the selection.
Thanks
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
mmm...it sounds like a dirty window painting, maybe caused by the high number of controls filled and enbled-disabled during the OnCreate....
what about trying Combobox1.doublebuffered := true....

this could be solve this problem as the painting should be less flickered....so more clean (no dirty colored parts i mean)  
0
 
KunfufaresiCommented:
Hello,

I tried it and no need to add panel or anything, just disabling it was enough to get the blue away, i use windows 2000 server and professional, what are you using? It might be an issue with your windows

when changing comobox1.color := RGB(0,0,0) the background is set to black, have you experimented with different color values, besides windows default names?

Also the way you describe your problem you seem to use style set to csDropDown have you tried csDropDownList? not that it made any difference with me.

if you create a new form with just 1 comobobox and fill it in with a few items and disable it does it still apear blue? that could at lead you to know if the issue is too many controls, too little memory stack etc.

Kunfu Faresi
0
 
shaneholmesCommented:
I think we all know that, and i think he knows that by now, that its not the normal behavior, we were merely suggesting ways to overcome his problem - hence my TPanel solution and Ferruccio68's paint solution....

<SMILE>

Shane
0
 
shaneholmesCommented:
Maybe just forcing a Repaint on the control, and/Or  a Application.ProcessMessages

Shane
0
 
hcarvajalAuthor Commented:
ComboBox1.Repaint does not changes the situation. I have tried the following:

ComboBox1.SelStart := 0;
 ComboBox1.SelLength := 0;  // set NO selected text
 ComboBox1.Repaint;
 ComboBox1.Enabled := true;
 ComboBox1.Enabled := false;

and the box is shown as selected. It seems to be something like an AutoSelect.

The piece of code which produces this situation occurs when the form is created, and is the following:

 if TmpStr = 'W' then ComboBox1.ItemIndex := 0 else
   if TmpStr = 'B' then ComboBox1.ItemIndex := 1;

If the form is enabled, disabled and then enabled the problem does not happens again (unless I exit from the form and call it again). I commented it out, and it showed the ComboBox as disabled, with no selected text.

Thank you.
0
 
kretzschmarCommented:
usual i can't reproduce the problem :-((

so that it may be, that it is a problem of your graphicdevice,
or you have somewhere your own painting routine
(maybe for the form)

otherwise just set the focus to an enabled control,
maybe followed with a repaint or invalidate of the form

meikl ;-)
0
 
__alexCommented:
ComboBox1.Style := csDropDown;

(I guess it is csDropDownList at the moment)
0
 
hcarvajalAuthor Commented:
The ComboBox style was csDropDown. I just changed to csDropDownList and this seems to work ok. The strange thing is that I tried to reproduce the form as a separate application having it as csDropDown and the problem does not occurs.
Thanks
0
 
KunfufaresiCommented:
Hello,

Have you tried running you orignial application outside Delphi, i mean close delphi and run the executable, it might be  that you run out of memory existing Delphi should free up some, if you exist all other software like internet explorer windows, msn, icq, etc. and try to run it will it still keep background

Kunfu Faresi
0
 
__alexCommented:
> The strange thing is that I tried to reproduce the
> form as a separate application having it as csDropDown
> and the problem does not occurs.

Focus the control an it gets blue again.
0
 
hcarvajalAuthor Commented:
The csDropDownList solved the issue. Running the application outside Delphi did not seem to help.
Thanks
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 6
  • 6
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now