I need to increase the font size of my menus (TMainMenu
, TPopupMenu
) and I cannot figure out how to do it correctly.
I thought I don't need to draw the menu items completely, so I just assigned OnMeasureItem
event and changed the Screen.MenuFont.Size
.
What I have done:
In dfm:
MainMenu.Ownerdraw = True
<EachMenuItem>.OnMeasureItem = MenuMeasureItem
In pas:
procedure TForm1.FormCreate(Sender: TObject);
begin
Screen.MenuFont.Size := 12;
end;
procedure TForm1.MenuMeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
var
mi: TMenuItem;
function IsTopLevel: Boolean;
var
k: Integer;
begin
Result := False;
for k := 0 to MainMenu.Items.Count - 1 do
begin
if mi = MainMenu.Items[k] then
begin
Result := True;
break;
end;
end;
end;
begin
Height := ACanvas.TextHeight('I') + 4;
mi := (Sender as TMenuItem);
if IsTopLevel then
Width := ACanvas.TextWidth(mi.Caption) + 4;
end;
Problems:
Heights of the top-level menu items remain the same (small) regardless of the
Screen.MenuFont.Size
.Heights of the top-level children in
MainMenu
are OK when no styles are used, but are not OK when I use styles (e.g. Carbon).Heights of the popup menu items are OK with and without styles, but when using, the font size of the menu items captions remains small, while without styles it scaled proportionally to the chosen
Screen.MenuFont.Size
.Right after the application launched, I see the following when no styles are applied (this problem is gone when using the styles):
the menu items of the top level are drawn in small font (Windows default), while the room for each item is scaled correctly accordingly to specified bigger font size (see the picture, part 1).
when I moving the mouse over a menu item, it starts to redraw with a bigger font size which I specified in
FormCreate
, and I see a mess here (see the picture, part 2).but after I move across all top-level menu items, they are started to look almost as I wanted them to be, except the height of the menu bar itself (see the picture, part 3).
So, are there any chances to fix the problems 1-4, or at least some of them, without implementing OnDrawItem
?
P.S. I know, I can use TActionBar
s or other (third-party) alternatives, but I am asking here about the standard menus.