如何将 16x16 图标与 TPopupMenu 中的菜单项正确对齐?

发布于 2025-01-14 01:17:42 字数 11686 浏览 1 评论 0原文

在 Delphi 11 Alexandria 的 Windows 10 中的 32 位 VCL 应用程序中,我在 TPopupMenu 中使用 16x16 像素图标。 不幸的是,这些图标没有与 TMenuItem 正确垂直对齐。标题:

在此处输入图像描述

在此处输入图像描述

这看起来很难看。如何正确对齐图标?

这些是项目选项中的清单设置:

在此处输入图像描述

这是重现问题的项目文件的源代码:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.ImageList, Vcl.ImgList,
  Vcl.Menus;

type
  TForm1 = class(TForm)
    ilMenus: TImageList;
    PopupMenu1: TPopupMenu;
    menuitem1: TMenuItem;
    menuitem2: TMenuItem;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

end.

这是表单文件:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 269
  ClientWidth = 454
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -12
  Font.Name = 'Segoe UI'
  Font.Style = []
  PopupMenu = PopupMenu1
  Position = poScreenCenter
  PixelsPerInch = 96
  TextHeight = 15
  object ilMenus: TImageList
    ColorDepth = cd32Bit
    DrawingStyle = dsTransparent
    Left = 18
    Top = 16
    Bitmap = {
      494C010101000800040010001000FFFFFFFF2110FFFFFFFFFFFFFFFF424D3600
      0000000000003600000028000000400000001000000001002000000000000010
      0000000000000000000000000000000000000000000000000000000000000000
      00001F170D2D6D4D2E979E7041DBB6804BFCB27D49F69D6F41DA71502E9C2318
      0D30000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000060502096E4D
      2D98B6814CFDB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB681
      4CFD72512F9F0906030C00000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000004030106876038BCB882
      4CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB882
      4CFFB8824CFF8F653BC60705030A000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000000000006C4C2D96B8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFF71502E9C000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000001F160C2CB6804BFCB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF0000000000000000B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB7814CFE251A0E330000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000067492B8FB8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF0000000000000000B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF72512F9F0000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000009B6E40D7B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF0000000000000000B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFFA17243E00000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000B37F4AF9B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF0000000000000000B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFFB8824CFF0000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000B37F4AF9B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF0000000000000000B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFFB47F4BFA0000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000009B6E40D7B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF0000000000000000B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFFA07142DE0000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000068492A90B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF735230A00000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000001F160C2CB6814CFDB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF0000000000000000B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF281D10380000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000000000006D4D2E97B8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFF735230A0000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000004030106896139BEB882
      4CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB882
      4CFFB8824CFF8E643AC50705030A000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000050401076D4E
      2E99B7814CFEB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB882
      4CFF72512F9F0605020900000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000251A0E336D4E2E999E7042DCB6814CFDB27E4AF79E7041DB71502E9C271C
      1036000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000424D3E000000000000003E000000
      2800000040000000100000000100010000000000800000000000000000000000
      000000000000000000000000FFFFFF00F00F000000000000C003000000000000
      8001000000000000800100000000000001800000000000000180000000000000
      0180000000000000018000000000000001800000000000000180000000000000
      0000000000000000018000000000000080010000000000008001000000000000
      C003000000000000F00F00000000000000000000000000000000000000000000
      000000000000}
  end
  object PopupMenu1: TPopupMenu
    Images = ilMenus
    Left = 24
    Top = 96
    object menuitem1: TMenuItem
      Caption = 'Menu Item 1'
      ImageIndex = 0
    end
    object menuitem2: TMenuItem
      Caption = 'Menu Item 2'
      ImageIndex = 0
    end
  end
end

In a 32-bit VCL Application in Windows 10 in Delphi 11 Alexandria, I use 16x16 pixel icons in a TPopupMenu. Unfortunately, the icons are not correctly aligned vertically to the TMenuItem caption:

enter image description here

enter image description here

This looks ugly. How can I align the icons correctly?

These are the Manifest settings from the Project Options:

enter image description here

Here is the source code of the project files to reproduce the problem:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.ImageList, Vcl.ImgList,
  Vcl.Menus;

type
  TForm1 = class(TForm)
    ilMenus: TImageList;
    PopupMenu1: TPopupMenu;
    menuitem1: TMenuItem;
    menuitem2: TMenuItem;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

end.

Here is the form file:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 269
  ClientWidth = 454
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -12
  Font.Name = 'Segoe UI'
  Font.Style = []
  PopupMenu = PopupMenu1
  Position = poScreenCenter
  PixelsPerInch = 96
  TextHeight = 15
  object ilMenus: TImageList
    ColorDepth = cd32Bit
    DrawingStyle = dsTransparent
    Left = 18
    Top = 16
    Bitmap = {
      494C010101000800040010001000FFFFFFFF2110FFFFFFFFFFFFFFFF424D3600
      0000000000003600000028000000400000001000000001002000000000000010
      0000000000000000000000000000000000000000000000000000000000000000
      00001F170D2D6D4D2E979E7041DBB6804BFCB27D49F69D6F41DA71502E9C2318
      0D30000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000060502096E4D
      2D98B6814CFDB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB681
      4CFD72512F9F0906030C00000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000004030106876038BCB882
      4CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB882
      4CFFB8824CFF8F653BC60705030A000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000000000006C4C2D96B8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFF71502E9C000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000001F160C2CB6804BFCB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF0000000000000000B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB7814CFE251A0E330000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000067492B8FB8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF0000000000000000B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF72512F9F0000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000009B6E40D7B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF0000000000000000B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFFA17243E00000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000B37F4AF9B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF0000000000000000B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFFB8824CFF0000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000B37F4AF9B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF0000000000000000B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFFB47F4BFA0000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000009B6E40D7B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF0000000000000000B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFFA07142DE0000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000068492A90B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF735230A00000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000001F160C2CB6814CFDB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF0000000000000000B8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFF281D10380000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000000000006D4D2E97B8824CFFB882
      4CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB882
      4CFFB8824CFFB8824CFF735230A0000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000004030106896139BEB882
      4CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB882
      4CFFB8824CFF8E643AC50705030A000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000050401076D4E
      2E99B7814CFEB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB8824CFFB882
      4CFF72512F9F0605020900000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000251A0E336D4E2E999E7042DCB6814CFDB27E4AF79E7041DB71502E9C271C
      1036000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000424D3E000000000000003E000000
      2800000040000000100000000100010000000000800000000000000000000000
      000000000000000000000000FFFFFF00F00F000000000000C003000000000000
      8001000000000000800100000000000001800000000000000180000000000000
      0180000000000000018000000000000001800000000000000180000000000000
      0000000000000000018000000000000080010000000000008001000000000000
      C003000000000000F00F00000000000000000000000000000000000000000000
      000000000000}
  end
  object PopupMenu1: TPopupMenu
    Images = ilMenus
    Left = 24
    Top = 96
    object menuitem1: TMenuItem
      Caption = 'Menu Item 1'
      ImageIndex = 0
    end
    object menuitem2: TMenuItem
      Caption = 'Menu Item 2'
      ImageIndex = 0
    end
  end
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文