Forum > Designer

Two problems with Combobox - text color and height

(1/1)

Przemyslav:
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:
I don't the answer to the first question but the second question is easy:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---ComboBox1.DropDownCount := 20;

balazsszekely:
@Przemyslav
Set Style property to csOwnerDrawFixed, then on DrawItem:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses LCLIntf, LCLType; procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;  ARect: TRect; State: TOwnerDrawState);var  Str: string;  CB: TComboBox;begin  CB := TComboBox(Control);  Str := CB.Items[Index];  if odSelected in State then     CB.Canvas.Brush.Color := clHighlight   else     CB.Canvas.Brush.Color := CB.Color;  CB.Canvas.FillRect(ARect);  CB.Canvas.Pen.Color := clRed;  DrawText(CB.Canvas.Handle, PChar(Str), Length(Str), ARect, DT_LEFT);end;

Przemyslav:
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.

Navigation

[0] Message Index

Go to full version