Solved

How to eliminate the blue background from a disabled combobox

Posted on 2004-04-28
19
421 Views
Last Modified: 2010-04-05
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
Comment
Question by:hcarvajal
  • 6
  • 6
  • 2
  • +4
19 Comments
 
LVL 11

Assisted Solution

by:shaneholmes
shaneholmes earned 200 total points
ID: 10942821
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
 

Author Comment

by:hcarvajal
ID: 10943082
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
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10943150
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
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10943156
Is your project big, maybe something you can zip and send me - so i can see

Shane
0
 

Author Comment

by:hcarvajal
ID: 10943344
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
 
LVL 33

Expert Comment

by:Slick812
ID: 10943619
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
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10943705
Is this a ComboBox or a DBComboBox?

Shane
0
 

Author Comment

by:hcarvajal
ID: 10944045
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
 
LVL 22

Assisted Solution

by:Ferruccio Accalai
Ferruccio Accalai earned 100 total points
ID: 10944179
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 3

Accepted Solution

by:
Kunfufaresi earned 200 total points
ID: 10944557
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
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10944581
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
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10944586
Maybe just forcing a Repaint on the control, and/Or  a Application.ProcessMessages

Shane
0
 

Author Comment

by:hcarvajal
ID: 10945821
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10946284
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
 
LVL 2

Expert Comment

by:__alex
ID: 10948512
ComboBox1.Style := csDropDown;

(I guess it is csDropDownList at the moment)
0
 

Author Comment

by:hcarvajal
ID: 10949243
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
 
LVL 3

Expert Comment

by:Kunfufaresi
ID: 10950293
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
 
LVL 2

Expert Comment

by:__alex
ID: 10956797
> 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
 

Author Comment

by:hcarvajal
ID: 10959361
The csDropDownList solved the issue. Running the application outside Delphi did not seem to help.
Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now