Set AdvPanel.Caption depending on Caption Fontsize


during the creation of an advanced panel, I set the font and size of the caption so it does fit.

During runtime, the font gets resized, but the height of the caption area stays the same, hence the caption heading bleeds into the content area.

In other parts of my application, I use the function Canvas.TextHeight(), but I have no idea how I could use it with the AdvPanel since there is no access to the canvas.

Any suggestion on how I could set the height of the caption based on the utilized caption font, either in code or via the properties?


Note: Delphi 11 fully patched, AdvPanel v2.6.1.0 on 4k monitor with 3840x2160, 175% scaling

TAdvPanel.Caption has a height property.


I properly wasn't clear enough. Setting the height of the caption is only half of the answer. The other one is to what should I set the height, or in other words, how can I figure out the height any given caption text is occupying?

As I wrote in my original post, if the canvas is accessible the Canvas.TextHeight(...) function can be used to get text metrics needed.

I have not found a way to get the needed text height. Any help, pointers for a workaround, or a general technique on how to do this would be greatly appreciated.


There is at this moment no such built-in function.
We added it now and in the next update it will be available as public function GetCaptionSize: TSize

Hello Bruno,

thank you so much for this info. Like always great service from you and your team.

Prior to reading your email, I found a workaround:

advPanel1.Caption.Background.Canvas.Font := advPanel1.Caption.Font;
advPanel1.Caption.Height := MulDiv(advPanel1.Caption.Background.Canvas.TextHeight('gh'), 96, Screen.PixelsPerInch);

Best regards,

That is indeed a possibility but the new GetCaptionSize will also return a correct size for possible wordwrapped or multiline HTML formatted text in the caption.

The GetCaptionSize is the way to go. I will change it as soon as I have the update installed on my computer.

Again, thanks for those great components and the great support.