简体   繁体   English

如何在Delphi上使用不同的图标大小?

[英]How to use different icon size on delphi?

Does anybody knows how to use diferent icons sizes on delphi, I ask because the windows choose the best icon size when showing on explorer, But how do I put many icons in different sizes on resource. 有人知道如何在delphi上使用不同的图标大小吗,我问是因为窗口在资源管理器上显示时选择了最佳图标大小,但是我如何在资源上放置许多不同大小的图标。

Thanks again 再次感谢

Here's how I do it: 这是我的方法:

  1. Prepare an icon file with an icon editing program. 使用图标编辑程序准备图标文件。 This file is a .ico file and contains multiple versions of the same icon with different sizes and pixel formats. 此文件是.ico文件,包含同一图标的多个版本,大小和像素格式不同。
  2. Reference that icon file in a .rc file that is used as source to the resource compiler. 在.rc文件中引用该图标文件,该文件用作资源编译器的源。
  3. As part of the compilation, the .rc file is processed, resulting in a .res file. 作为编译的一部分,将处理.rc文件,从而生成一个.res文件。
  4. Link the .res file to the executable with a $R directive. 使用$R指令将.res文件链接到可执行文件。
  5. At runtime load the appropriate version of the icon with one of the Windows API functions that loads images from resources. 在运行时,使用从资源加载图像的Windows API函数之一加载适当版本的图标。

I use these steps for all the icons that I use on toolbars and menus. 我将这些步骤用于工具栏和菜单上的所有图标。 That allows me to have a GUI that scales with the user's font scaling settings. 这样一来,我就可以拥有可根据用户的字体缩放设置进行缩放的GUI。 The way that the Delphi IDE leads you to do it is to make a TImageList and fill it up with icons that are stored in the .dfm file. Delphi IDE引导您完成此操作的方法是制作一个TImageList并用存储在.dfm文件中的图标填充它。 That's pretty hopeless because it doesn't readily allow you to have different sized icons. 这是完全没有希望的,因为它不能轻易让您拥有不同大小的图标。 And it also means that your visual assets are stored in a .dfm file in a great big glob representing all icons. 这也意味着您的视觉资产存储在一个.dfm文件中,该文件很大,代表所有图标。 If you want to swap out a single icon, then you can do so but it's rather opaque. 如果要换出单个图标,则可以这样做,但是它很不透明。 The history trail left in your VCS is meaningless beyond any comments you leave. VCS中留下的历史记录对您留下的任何评论都毫无意义。

If you are just talking about the main program icon, then you can add your .ico file to the project in the Project | 如果您只是在谈论主程序图标,则可以将.ico文件添加到“项目” |项目”中。 Options | 选项| Application dialog and the IDE will take care of the rest of the details. 应用程序对话框和IDE将处理其余的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM