[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 978
  • Last Modified:

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
0
tirbanqs
Asked:
tirbanqs
  • 2
  • 2
1 Solution
 
Geert GruwezOracle 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
 
tirbanqsAuthor Commented:
Thanks a lot.
0
 
Geert GruwezOracle 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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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