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?
 
ben-thompsonConnect With a Mentor Commented:
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.