Jump to content
A.M. Hoornweg

tMainmenu DPI issue

Recommended Posts

Hello all,

 

I have the problem that tMainmenu often fails to re-scale properly if I drag a window from a low-dpi screen to a high-dpi screen. This happens especially if it is a complex menu and it happens with or without a tVirtualImageList attached. The problem occurs on both Windows 10 and 11 (but more frequent on Windows 11).

 

The compiler I use is Delphi 11.1 Alexandria.  I am looking for workaround, is there a way to manually re-initialize or re-build the tMainmenu after scaling ?

mainmenu_before_resize.png

mainmenu_after_resize.png

Share this post


Link to post

I managed to create a workaround for this. See code below.

 

The mainmenu of the form can be re-initialized by calling "menu.rebuild" . 

It works best if this is done  ~100 ms after the form is re-scaled to the new dpi.

 

 

 

type
  tMenuItemHack = class helper for tMenuItem
    procedure RebuildMenu;
  end;

  tMainmenuHack = class helper for tMainmenu
    procedure Rebuild;
  end;

procedure tMenuItemHack.RebuildMenu;
begin
  menuchanged(True); //"Protected" method
end;

procedure tMainmenuHack.Rebuild;
var
  cnt: Integer;
  item: tMenuItem;
begin
  cnt := items.Count;
  if cnt > 0 then
  begin
    item := items[cnt-1]; 
    item.RebuildMenu;// trigger "menuchanged(True)" on rightmost item (minimize flicker)
  end;
end;

 

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×