Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

Display an Icon on TBitBtn Delphi control with the help of TImageList

Use an Icon for a Glyph on a TBitBtn Delphi control with the help of TImageList

By Zarko Gajic, About.com

Icon on a TBitBtn

Icon on a TBitBtn

The TBitBtn Delphi control is a button control that can include a bitmap on its face.

The Glyph property specifies the bitmap that appears on the bitmap button.

By design, the Glyph property can only display BMP (Windows Bitmap) images.

If you need to display an icon (ICO) file on a BitBtn, you can use the next trick:

  1. Drop a TImageList on a form. The TImageList (Win32 palette) represents a collection of same-sized images, each of which can be referred to by its index.
  2. Assign several icons to the ImageList. Do it by double-clicking on the ImageList control at design time and use the ImageList designer.
  3. Use the next code to draw the first two ICOns in he ImageList onto BitBtn1 and BitBtn2:
ImageList1.GetBitmap(0, BitBtn1.Glyph) ;
ImageList1.GetBitmap(1, BitBtn2.Glyph) ;
That's all.

Note how the TImageList control also exposes the GetIcon method you can use to obtain a particular image in the image list as an icon.

Delphi tips navigator:
» Create Collapsible Code Blocks in Delphi Code Editor using the {$REGION} directive
« Understanding ScreenToClient and ClientToScreen Delphi methods

More Delphi Programming Quick Tips
Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. Delphi 2007 Tips
  7. Use an Icon for a Glyph on a TBitBtn Delphi control with the help of TImageList

©2009 About.com, a part of The New York Times Company.

All rights reserved.