Can a cell in desktoplistbox contain different fontsizes in one cell

I am busy to make an application with a desktoplistbox containing menu’s (like in restaurant) which does have the name of a head course (like Tournedos in fontsize 18) which underneath a simple explanation what is in this meal (like: creamsaus | mushrooms | french frites | salat in fontsize 14)

The idea is to get in one cell:
TOURNEDOS
creamsaus | mushrooms | french frites | salat

Is that possible and if it is, how? I am busy for some time with it (paint cell, etc.) but the whole cell gets the same fontsize.

You’ll have to use the CellTextPaint event and draw your text yourself there. Since it passes a graphics object, use it to draw your various pieces of text.

6 Likes

There was an article series “*OOP Listbox” in xDev (18.6 had the last part). You can download the project from the xDev website here

Alternatively you could just google a short summary on how to do it with “Best programming practises: the ListBox”

It’s actually quite simple. You use the PaintCellText event for this. There, you use the g.DrawText method to write the text to the Graphics object after defining the font, size, etc. Finally, you exit the event with a Return True, thus telling the system that you have taken over the drawing of the cell’s contents yourself.

This could then look like this, for example:

  // === BODY SECTION ===
  g.FontSize = 11
  g.Bold = False
  
  If Not isRowSelected Then
    g.DrawingColor = Color.DarkGray
  End If
  
  Var bodyTag As Variant = Me.CellTagAt( row, 4 )
  If bodyTag <> Nil Then
    g.DrawText( bodyTag.StringValue, x, y + 2, g.Width - 2 )
  End If

...

Return True

Which in turn results in a cell that looks something like this (I have obscured some information for privacy reasons):
Screenshot-2

1 Like

Thank you Sacha!

1 Like