* * *

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

Przemyslav

  • New member
  • *
  • Posts: 26
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

  • Jr. Member
  • **
  • Posts: 75
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;
Started with OmegaSoft Pascal on OS-9/68k , now Lazarus 1.8 RC4 / FPC 3.0.4rc1 on Windows 7

GetMem

  • Hero Member
  • *****
  • Posts: 2247
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: 26
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.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus