Recent

Author Topic: Two problems with Combobox - text color and height  (Read 4328 times)

Przemyslav

  • New Member
  • *
  • Posts: 44
Two problems with Combobox - text color and height
« on: March 06, 2017, 04:44:09 pm »
Hello everybody :) I have problem with ComboBox. For example I have like this:

(https://s15.postimg.org/l5253hjpj/Bez_tytu_u.png)

I set color of font to red, but all my items are black? What i do wrong?
Second question: Can I resize the white field with my items, I'm talking about height this field. When I have much more items, this field is too small in height direction.

fred

  • Full Member
  • ***
  • Posts: 201
Re: Two problems with Combobox - text color and height
« Reply #1 on: March 06, 2017, 05:10:48 pm »
I don't the answer to the first question but the second question is easy:

Code: Pascal  [Select][+][-]
  1. ComboBox1.DropDownCount := 20;

balazsszekely

  • Guest
Re: Two problems with Combobox - text color and height
« Reply #2 on: March 06, 2017, 05:25:31 pm »
@Przemyslav
Set Style property to csOwnerDrawFixed, then on DrawItem:
Code: Pascal  [Select][+][-]
  1. uses LCLIntf, LCLType;
  2.  
  3. procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  4.   ARect: TRect; State: TOwnerDrawState);
  5. var
  6.   Str: string;
  7.   CB: TComboBox;
  8. begin
  9.   CB := TComboBox(Control);
  10.   Str := CB.Items[Index];
  11.   if odSelected in State then
  12.      CB.Canvas.Brush.Color := clHighlight
  13.    else
  14.      CB.Canvas.Brush.Color := CB.Color;
  15.   CB.Canvas.FillRect(ARect);
  16.   CB.Canvas.Pen.Color := clRed;
  17.   DrawText(CB.Canvas.Handle, PChar(Str), Length(Str), ARect, DT_LEFT);
  18. end;

Przemyslav

  • New Member
  • *
  • Posts: 44
Re: Two problems with Combobox - text color and height
« Reply #3 on: March 06, 2017, 05:31:16 pm »
Thanks you very much :) I will try it. In first I was shocked, that color font which I have chosen in properties wasn't working.

 

TinyPortal © 2005-2018