In Delphi, Button and Icon

Jean-Marie DUBASIK -  
 php -
Hello,

I would like to put icons in my command buttons.
Is it possible?
A tip, please?
Thank you for your help
Jean-Marie DUBASIK

5 réponses

sebsauvage Posted messages 33284 Registration date   Status Modérateur Last intervention   15 684
 
You can use the TSpeedButton or the TBitBtn
(check the Delphi help).

Both allow you to set the image or icon of your
choice, with or without text.
1
Jean-Marie DUBASIK
 
Thank you for your help.
However, I agree that I might be a bit heavy-handed; I don't see the possibility of adding .BMP files, whereas I would like to include .ICO files.
Could you please specify how to add .ICO files?
Thank you.
1
sebsauvage Posted messages 33284 Registration date   Status Modérateur Last intervention   15 684
 
You can convert your BMP files to ICO using different software.
For example, XNView (which can read over 300 different image formats... an excellent French program that I recommend), or simpler: display the icon on the screen, press the 'Print Screen' key, save the clipboard as BMP...

XNView: http://www.xnview.com/
(oh look! They bought a domain name, that's good).
0
Jean-Marie DUBASIK
 
Hello,
Thank you for taking the time to respond.
Actually, what I need is to use .ICO files and not .BMP files. .BMP files are too large and I have .ICO files.
Maybe the XNVIEW program converts *.ICO to *.BMP, but I'm worried about the space it will take up in the program.
0
sebsauvage Posted messages 33284 Registration date   Status Modérateur Last intervention   15 684
 
Technically, the same image will take up practically the same space in ICO and BMP (since both formats are uncompressed anyway).

You can safely use the BMP format.

However, once your EXE is finished, you can compress it (for example with the excellent UPX: http://upx.tsx.org).
0
php
 
Hi JMD

If you absolutely want to use icons, you can use the
ToolBar in the Win32 palette associated with an ImageList as long as you're using Delphi 4 (I don't know if it works with previous versions)

ToolBars are heavier to handle than simple buttons because, as their name indicates, they are designed to manage toolbars. But it works even with just one button.

So first, place a TImageList object on your form.
Note that all your icons must be the same size!
Before loading any icons into the list, first modify the Height and Width properties to match the dimensions of your icons.

Then double-click your image list and load your icons into it

Now place a ToolBar object on your form.
Then link its Image property to your image list ImageList1 for example.
Then right-click the ToolBar [New button]
The first button automatically inherits the first icon that you stored in your image list, the second button the second, and so on. Naturally, you can change the displayed image for the button by changing its ImageIndex property: set it to -1 if you don't want an image.

You can even define a second image list with icons representing the same disabled buttons and associate this list with the DisabledImages property of the ToolBar. So when the Enabled property of one of the buttons changes, the image it displays also changes!

Same with the HotImages property of the ToolBar, but this time the button's image changes when the mouse hovers over the button!

And there you go
@+
Philippe
0