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

Left Align Caption of a TSpeedButton Delphi button
Left Justify TSpeedButton's Caption (and more)

By , About.com Guide

TSpeedButton Left Aligned Caption

TSpeedButton Left Aligned Caption

Delphi provides three "standard" button types for your applications : TButton, TBitButton and TSpeedButton. The TButton is a wrapper for the standard Windows push button control.

TBitBtn (bitmap button) which provides properties that specify the bitmap images, along with their appearance and placement on the button.

TSpeedButton introduces properties that allow speed buttons to work together as a group.

TSpeedButton Glyph and Caption and Layout

In general, when you need graphics on a button you'll use a TBitBtn. When you are building a toolbar you'll use a TSpeedButton. The Glyph property of a TSpeedButton let's you select a bitmap image to be displayed in a button to represent different button states (selected, unselected, disabled and so on).

The Layout property determines where the image or text appears on the speed button. The image can be placed left to the button caption, right, above or below.

TSpeedButton Caption Alignment

When you have a group of speed buttons one after another in vertical "line", with Layout set to blGlyphLeft the buttons do not look so nice.

What you might start looking for is the "Caption Layout" property to let you set the alignment of the button caption. Sadly, you'll find no such property :( Or, would you?

TSpeedButton and the Margin property

The TSpeedButton's Margin property specifies the number of pixels between the edge of the button and the image or caption drawn on its surface.

When Margin is –1, the default value, the image or text is centered on the button.

If you want the caption to be aligned left you need to specify the indentation of the image specified by the Glyph property or the text specified by the Caption property.

The edges that Margin separates depends on the Layout property.

  • When Layout is blGlyphLeft, the margin appears between the left edge of the image or caption and the left edge of the button.
  • When Layout is blGlyphRight, the margin separates the right edges.
  • When Layout is blGlyphTop, the margin separates the top edges.
  • When Layout is blGlyphBottom, the margin separates the bottom edges.
Therefore when a speed button has a Glyph with Layout set to blGlyphLeft and you want the Caption also to align left - just specify Margin to a positive value.

Yes, that simple.

Delphi tips navigator:
» Calculating the Zodiac Sign from the Birth Date
« Handling Global Application Object Events in Delphi

More Delphi Programming Quick Tips
Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. Delphi 2008 Tips
  7. TSpeedButton Left Align Caption - Left Justify Delphi's TSpeedButton Caption Text

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

All rights reserved.