Is there a way in which the TComboBox drop down button is always hidden ?

I am using Delphi 6

Is there a way in which the TComboBox drop down button
is always hidden ?  (See attached Image)
I am using a TComboBox with
6 blank items.
 
'Style' = 
csOwnerDrawVariable
 
On the event 'OnDrawItem'
,
-------
 
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
 with TComboBox(Control) do
 begin
   case Index of
     0 : Canvas.Brush.Color := clWhite;
     1 : Canvas.Brush.Color := clRed;
     2 : Canvas.Brush.Color := clBlue;
     3 : Canvas.Brush.Color := clAqua;
     4 : Canvas.Brush.Color := clGreen;
     5 : Canvas.Brush.Color := clYellow;
   end;
   Canvas.FillRect(Rect);
 end;
end;

Open in new window

ComboBox.jpg
tirbanqsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert GOracle dbaCommented:
wouldn't it be easier to use an owner drawn Listbox ?

fill the items from the Listbox from 0 to 5
set Listbox.Style = lbOwnerDrawFixed;

the listbox will remain visible
or did you have something else in mind ?
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
 with TListbox(Control) do
 begin
   case Index of
     0 : Canvas.Brush.Color := clWhite;
     1 : Canvas.Brush.Color := clRed;
     2 : Canvas.Brush.Color := clBlue;
     3 : Canvas.Brush.Color := clAqua;
     4 : Canvas.Brush.Color := clGreen;
     5 : Canvas.Brush.Color := clYellow;
   end;
   Canvas.FillRect(Rect);
 end;
end;

Open in new window

0
ben-thompsonCommented:
It's quite difficult to properly remove the button, you could set the style to csSimple, but then you won't be able to override the drawing of the items.

If you make your own component then you can just draw over the button (see code). You can also set the Canvas.Brush.Color in WMPaint to display the colour a user has picked, I think.
type
  TNoButtonCombo = class(TComboBox)
  private
    procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
  end;
 
implementation
 
procedure TNoButtonCombo.WMPaint(var Message: TWMPaint);
var
  R : TRect;
begin
  inherited;
 
  R := ClientRect;
  InflateRect(R, -2, -2);
  Canvas.FillRect(R);
end;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tirbanqsAuthor Commented:
Thanks a lot.
0
Geert GOracle dbaCommented:
you could just as easily have put a TPanel on top of the Combobox where the  DropDown Button is
set the Caption to '' and set the BevelOuter to bvNone, no need for custom drawing
0
ben-thompsonCommented:
Interesting point, but surely then there would be an area of the combo that didn't respond to clicks, you'd need to override messages to get that to work.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.