Creating the Component s Tool Palette Icon


Creating the Component's Tool Palette Icon

The following figure shows our two components (TSimple and TStringsCache) on the Designer Surface. But how do you really know that Figure 24-20 shows both a TSimple and a TStringsCache component?

image from book
Figure 24-20: The TSimple and TStringsCache components on the Designer Surface

Although the default component icon isn't ugly, you should always change it when you create a new component.

The following steps show how to create a Tool Palette icon for the TStringsCache component:

  1. Open the Image Editor by selecting Tools ® Image Editor.

  2. Create a new component resource file by selecting File ® New ® Component Resource File (.dcr) in the Image Editor.

  3. Save the new .dcr file in the component's directory. The file name of the .dcr file must match the file name of the component. So, if the TStringsCache component's unit is image from book StringsCache.pas, you have to save the .dcr file under image from book StringsCache.dcr.

  4. Now right-click the Contents node in the image from book StringsCache.dcr window and select New ® Bitmap to display the Bitmap Properties dialog box (see Figure 24-21).

    image from book
    Figure 24-21: Creating a Tool Palette icon in the Image Editor

  5. The Tool Palette icon should be a 24x24 bitmap, so update the Width and Height text boxes. You should also select the SuperVGA option if you want to have a nice-looking icon.

  6. When you click OK to create the new bitmap, it will be named Bitmap1. You must change the bitmap's name to match the class name of the component. In this case, you have to rename the bitmap TStringsCache (the Image Editor will automatically convert the name to uppercase).

  7. Now you need to draw a nice component icon.

  8. Finally, when you're done drawing or pasting the image from an external source, save the .dcr file and return to the Project Manager.

  9. Right-click the image from book StringsCache.pas file in the Project Manager and select Remove from Project to temporarily remove the TStringsCache component from the package.

  10. Right-click the package icon (Package1.bpl, or whatever it's called), select Add…, and add the image from book StringsCache.pas file back to the package. Since the directory now contains both the .pas file and the .dcr file, the IDE will automatically add both files to the package.

  11. Finally, recompile the package and you're done. (If you cannot see the new icon, try restarting Delphi to reload the package.)

    Figure 24-22 shows the new component icon in the IDE.

    image from book
    Figure 24-22: The new component icon



Inside Delphi 2006
Inside Delphi 2006 (Wordware Delphi Developers Library)
ISBN: 1598220039
EAN: 2147483647
Year: 2004
Pages: 212
Authors: Ivan Hladni

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net