ActionMainMenuBar带有32x32图标

Gu.*_*u. 2 delphi action-menu

德尔福Xe4.表单,ActionManager,ImageList(带有32x32图标),ActionMainMenuBar.

我无法确保图标显示正确.你该怎么办?

PIC1

同时,如果我应用任何vcl风格的装饰,它显示正常.但是,如果默认情况下为"Windows"样式,则文本会移出图标.救命.

PIC2

PIC3

PIC4

对不起英语不好.

Ser*_*yuz 6

这是一个有效的问题,TActionMainMenuBar旨在将自定义图标大小作为菜单图像处理,就像本机菜单可以很好地处理它们一样.可以在代码中的注释中找到一个指示,在下面的VCL代码中可以找到注释16 is standard image size so adjust for larger images.

我相信错误的代码TCustomMenuItem.CalcBounds在'ActnMenus.pas'中.以下摘录自D2007.请注意下面的行我用一些感叹号评论.在上升类TCustomActionControl计算文本和图像在其CalcLayout方法中的位置之后,在所述语句TCustomMenuItem中用硬编码的24对其进行破坏.

procedure TCustomMenuItem.CalcBounds;
var
  AWidth, AHeight: Integer;
  NewTextBounds: TRect;
  ImageSize: TPoint;
  ImageOffset: Integer;
begin
  inherited CalcBounds;
  ImageSize := GetImageSize;
  AHeight := FCYMenu;
  if Separator then
    AHeight := FCYMenu div 3 * 2
  else
    // 16 is standard image size so adjust for larger images
    if ImageSize.Y > 16 then
      AHeight := ImageSize.Y + 4;
  if ActionClient = nil then exit;
  if ImageSize.X <= 16 then
    ImageOffset := 24
  else
    ImageOffset := ImageSize.X + 6;  // Leave room for an image frame
  NewTextBounds := TextBounds;
  OffsetRect(NewTextBounds, 24 - TextBounds.Left,          // <- !!!!!
    AHeight div 2 - TextBounds.Bottom div 2 - 1);
  TextBounds := NewTextBounds;
  ShortCutBounds := Rect(0,0,0,0);
  if ActionClient.ShortCut <> 0 then
  begin
    Windows.DrawText(Canvas.Handle, PChar(ActionClient.ShortCutText), -1,
      FShortCutBounds, DT_CALCRECT);
    // Left offset is determined when the item is painted to make it right justified
    FShortCutBounds.Top := TextBounds.Top;
    FShortCutBounds.Bottom := TextBounds.Bottom;
    AWidth := TextBounds.Right + FShortCutBounds.Right + ImageOffset + Spacing;
  end
  else
    AWidth := TextBounds.Right + TextBounds.Left;
  SetBounds(Left, Top, AWidth, AHeight);
end;
Run Code Online (Sandbox Code Playgroud)


24是基于具有16倍或更少的像素宽度的图像的假设.应该使用的是ImageOffset仅计算上面几行的值.更换

  OffsetRect(NewTextBounds, 24 - TextBounds.Left,
    AHeight div 2 - TextBounds.Bottom div 2 - 1);
Run Code Online (Sandbox Code Playgroud)

  OffsetRect(NewTextBounds, ImageOffset - TextBounds.Left,
    AHeight div 2 - TextBounds.Bottom div 2 - 1);
Run Code Online (Sandbox Code Playgroud)

你会有这样的事情:

删除菜单

你会注意到其他一些奇怪的东西,没有图像的物品仍然可以用于小图像布局.IMO所有菜单项应具有相同的基本布局,但操作菜单的设计允许单个项目的不同布局.另一个奇怪的事情是带有图像的项目的检查状态('Action6'),虽然我不确定我是否在这里错过了一个设置,或者它是否有资格作为一个bug.