4

I'm trying to change the font size of a combobox in Delphi Firemonkey XE7. The application will be used on a Windows tablet. It already works so far that the selected item shown in the combobox when "not opened" changes the font size but when I click on the combobox and the drop-down-menu opens, the items in the drop-down-menu have still the default font size. Does anyone know how to fix this?

The source code so far:

for i := 0 to combobox1.Count - 1 do
begin
  combobox1.ListBox.ListItems[i].TextSettings.Font.Size := 20;
  combobox1.ListBox.ListItems[i].StyledSettings :=  combobox1.ListBox.ListItems[i].StyledSettings - [TStyledSetting.Size];
end;

Click here to view picture of the described problem.

Thanks in advance! Lea

MCMastery
  • 3,099
  • 2
  • 20
  • 43
Lea
  • 261
  • 5
  • 14
  • If you use the Scale property on the combobox it will change the text size of both the box item and the drop down items. – Doug Rudd Jul 22 '15 at 18:51
  • 1
    do you have any code? what i read on the internet about the property seems that it just scales the drop-down-menu but not the font size but i have no idea if that's right and how to use this property :/ – Lea Jul 23 '15 at 07:26

2 Answers2

4

For use styled ListBox items in ComboBox, set ComboBox.DropDownKind := TDropDownKind.Custom

kami
  • 1,438
  • 1
  • 16
  • 23
  • thanks! that worked. but now the space around the drop-down-item-texts is quite small. can i somehow get a bigger margin or something like that? – Lea Jul 23 '15 at 12:10
  • Set ComboBox.ItemHeight. I think, that is better to create custom styles for ComboBox and ListBoxItem for centralized management of properties – kami Jul 23 '15 at 12:20
1
Procedure StyleComboBoxItems(ComboBox:TComboBox; Family:string; Size:Single);
var
  Item : TListBoxItem;
  i : Integer;
begin
  for i := 0 to ComboBox.Count-1 do begin
    Item := ComboBox.ListItems[i];
    Item.Font.Family := Family; //'Arial';
    Item.Font.Size := Size; //20;
    // Item.FontColor := TAlphaColorRec.Red;
    Item.StyledSettings := Item.StyledSettings - [TStyledSetting.Family,TStyledSetting.Size,TStyledSetting.FontColor];
    // Item.Text := '*'+Item.Text;
  end;
end;

//call like StyleComboBoxItems(cbbXYZ,'Segoe UI',10.0);
//remember to call it everytime you change the cbb list by clearing, adding, deleting etc.

Code by JAN BLOMQVIST

Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54
user30478
  • 347
  • 1
  • 3
  • 13