[Lazarus] TStatusBar.AutoSize doesn't work (Lazarus 2.12, Win32)

Rolf Wetjen rolf.wetjen at mail.de
Tue Sep 28 10:30:23 CEST 2021

Hi everybody,

TStatusBar.AutoSize doesen't work. The size of the statusbar is always a 
default size.


"The height is based on the metrics of the font that is currently 
selected into the status bar's device context and on the width of the 
window's borders." LCL uses TWin32WidgetSet(WidgetSet).AppHandle to 
creates a dummy child window and calculates the statusbar height from 
this dummy window. There are three issues with this approach:

 1. The font of the AppHandle window isn't the one LCL uses for the
    StatusBar object (StatusBar1.Font). So the calculated height doesn't
    fit for a large font.
 2. AppHandle is not set if the statusbar parent form is created within
    a DLL (I'm using CreateNew for my deskband dll). Issue #37100.
 3. The procedure InitializePreferredStatusBarHeight is called only once
    and will not recalculate on font changes.

The attached file win32wscomctrls.pp has two small changes to solve this:

Use Parent := GetDesktopWindow instead of 
This is a wrong in the same way as TWin32WidgetSet(WidgetSet).AppHandle 
but should always work.

Calculate the statusbar height from AWinControl.Font.Height on each 
call. Use InitializePreferredStatusBarHeight as a fallback and only once 
if needed.

Shall I open an issue for this?

Thank you for all comments.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20210928/b32d293a/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test1.zip
Type: application/x-zip-compressed
Size: 5064 bytes
Desc: not available
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20210928/b32d293a/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: win32wscomctrls.zip
Type: application/x-zip-compressed
Size: 9179 bytes
Desc: not available
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20210928/b32d293a/attachment-0003.bin>

More information about the lazarus mailing list