2
votes

I'm learning about FireMonkey styles - my main reference has been here. Everything I've tried with simple labels and shapes has worked fine but I'm now working with a TListBox and trying to do two things:

  1. Set the font of items in a TListBox.
  2. Remove its border (it's client aligned in a TCalloutPanel).

I am using the method of creating a StyleBook on the form, right-clicking the control and choosing 'Edit Custom style'. (I'd be equally happy to make runtime changes though).

The only success I've had with the font is to create multiple TListBoxItem's and use their individual text settings. Is there no way of them inherited a parent setting as with VCL? I would really like to add list box items simply as in the VCL with:

 ListBox1.Items.Add( 'text' )

but I cannot see a run time way of getting at the internal TListBoxItem array that I see is created.

The other problem is that I can see no way of removing the border rectangle. A plain rectangle is easy - it has a stroke - but digging through all the layout options of a TListBox in the StyleBook I just cant see a stroke anywhere.

I'm using XE7. Am I missing something?

Thanks for any help.

1
TListBox has a property DefaultItemStyles which is probably what you want but is undocumented so needs some investigation. Removing the outline is more complicated. Check out the Bitmap Style Designer (on the Tools menu) and you'll need a good graphics editor.Mike Sutton

1 Answers

3
votes

There is no guarantee that the background will be of TRectangle type.

When you choose the Edit Custom Style option you will be editing a platform default style which is always a Windows style. (That is, if no custom style has been loaded already)

The way they decided to handle platform default styles is by taking snapshots of native controls and merging them in a single image from which they can individually sourcelink to a specific control. That image is available in the style for you to modify.

  1. Setting font of items in a ListBox

    Right click on item and select Edit Custom Style, a new style object is added to your StyleBook. For the listbox item it should be called listboxitem1style1 altho numbers can vary.(The name comes from the default style for this object which is listboxitemstyle).

    This is the style object that you want to edit in the StyleBook. Once you are done, close the StyleBook and change the StyleLookup property of each ListBox item to listboxitem1style1. Preferably you should assign the value to the property at runtime.
    ListBoxItem1.StyleLookup := 'listboxitem1style1';

  2. Removing border from TListBox

    After the custom style is loaded in your StyleBook, using Style designer, navigate to ListBox1Style1 > background : SourceLink property and edit the SourceRect of the assigned BitmapLink object. Basically you inflate the rectangle by -2 to get rid of the border.

enter image description here