Hi everybody,

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

From https://docs.microsoft.com/en-us/windows/win32/controls/status-bars#size-and-height <https://docs.microsoft.com/en-us/windows/win32/controls/status-bars#size-and-height>:

"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:

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

TWin32WSStatusBar.GetPreferredSize
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.

Rolf

<<attachment: test1.zip>>

<<attachment: win32wscomctrls.zip>>

-- 
_______________________________________________
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus

Reply via email to