最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

delphi - Changing top level menu items font - Stack Overflow

programmeradmin2浏览0评论

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:

  1. Heights of the top-level menu items remain the same (small) regardless of the Screen.MenuFont.Size.

  2. 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).

  3. 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.

  4. 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 TActionBars or other (third-party) alternatives, but I am asking here about the standard menus.

发布评论

评论列表(0)

  1. 暂无评论