Avatar of hakanfa
hakanfa
Flag for Finland asked on

Background text in ComboBox/TextEdit

Hello Experts,
is there any components/easy way to show the selection as a background in ex. a Combobox. Im trying to mimic the behavior of the search-combobox in IE 7. (showing the selected search engine as background text)

Kind regards,
-Hokki
Delphi

Avatar of undefined
Last Comment
hakanfa

8/22/2022 - Mon
tobjectpascal

i've not seen v7 of ie, what's it look like? screenshot?
hakanfa

ASKER
Hello, please see attached screenshot. Same behavior you can find in Vista "Start Search" in taskbar.
dhot1.jpg
wd123

i think you can do like this:
1. set text in ComboBox/TextEdit - (for example 'google') and change a font size or color for it (color - grey, like in your example)  
2. onmouseclick events you just clear it, and change font size or color for ComboBox/TextEdit again to default (color - black)
3. onchange events you check if text='' (empy) you again set your default word ('google') and font color (grey).
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ThievingSix


procedure TForm1.FormCreate(Sender: TObject);
begin
 Edit1.Font.Color := clGray;
 Edit1.Text := 'Google';
end;
 
procedure TForm1.Edit1Enter(Sender: TObject);
begin
  Edit1.Text := '';
  Edit1.Font.Color := clBlack;
end;
 
procedure TForm1.Edit1Exit(Sender: TObject);
begin
 Edit1.Font.Color := clGray;
 Edit1.Text := 'Google';
end;

Open in new window

Geert G

There is a combobox on the Windows32 component list called ComboboxEx.
Place one on your form.  Place a TImageList on your form.  Create a simple bmp with the image editor with Google in it with size something like 60x18.  You could even add the google colors.  or any other pic for that matter.
There is 1 problem with this component.  The ItemIndex does not appear at desgintime.  Therefore you need to set it at runtime
And use the below code.

procedure TForm1.FormCreate(Sender: TObject);
begin
  ComboBoxEx1.ItemIndex := 0;
end;
 
procedure TForm1.ComboBoxEx1Enter(Sender: TObject);
begin
  ComboBoxEx1.StyleEx := ComboBoxEx1.StyleEx + [csExNoEditImage, csExNoEditImageIndent];
end;

Open in new window

Geert G

Oh yeah, forgot to mention you need to link the imagelist to the comboboxex.  Create an item in the ItemsEx list with the imageindex from the imagelist.  You could create multiple images for all the search engines
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
reynaldio

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
hakanfa

ASKER
Dear all,
thank You for all good comments, especially Reynaldi for his fabulous solution!

Thank You,
-Hakan