Previous Topic

Next Topic

Inhoudsopgave

Book Index

TSpeedButton Control

TSpeedButton

Description

Use TSpeedButton to add a button to a group of buttons in a form. TSpeedButton introduces properties that can be used to set graphical images that represent the different button states (selected, unselected, disabled and so on).

If you are not using an action to respond when the user clicks the button, then you can specify the button's response by writing an OnClick event handler.

Tip: To create a speed button with a client-aligned glyph that covers the button's edges, add a 1-pixel margin around the button's top and left edges and a 3-pixel margin around its bottom and right edges. Do this by manually editing the bitmap specified by the Glyph property.

TSpeedButton Properties

Property Property Caption: String (R/W)

Use Caption to specify the text string that labels the control.

Property Property GroupIndex: Integer (R/W)

Set GroupIndex to determine how the button behaves when clicked.

When GroupIndex is 0, the button behaves independently of all other buttons on the form. When the user clicks such a speed button, the button appears pressed (in its clicked state) and then returns to its normal up state when the user releases the mouse button.

When GroupIndex is greater than 0, the button remains selected (in its down state) when clicked by the user. When the user clicks a selected button, it returns to the up state, unless Caption is false. Setting the GroupIndex property of a single speed button to a value greater than 0 causes the button to behave as a two-state button when Caption is true.

Speed buttons with the same GroupIndex property value (other than 0), work together as a group. When the user clicks one of these buttons, it remains selected until the user clicks another speed button belonging to the same group. Speed buttons used in this way can present mutually exclusive choices to the user.

Property Property Glyph.LoadFromFile: String (R/W)

Specifies the bitmap that appears on the speed button.

Glyph can provide up to four images within a single bitmap. All images must be the same size and next to each other in a horizontal row. TSpeedButton displays one of these images depending on the state of the button.

Image position

Button state

Description

First

Up

This image appears when the button is unselected. If no other images exist in the bitmap, this image is used for all states.

Second

Disabled

This image usually appears dimmed to indicate that the button can't be selected.

Third

Clicked

This image appears when the button is clicked. If GroupIndex is 0, the Up image reappears when the user releases the mouse button.

Fourth

Down

This image appears when the button stays down indicating that it remains selected.

If only one image is present, TSpeedButton attempts to represent the other states by altering the image slightly for each state, although the Down state is always the same as the Up state.

If the bitmap contains multiple images, specify the number of images in the bitmap with the NumGlyphs property.

Note: The lower left pixel of the bitmap is reserved for the 'transparent' color. Any pixel in the bitmap that matches the lower left pixel will be transparent.

Property Property Glyph.SaveFromFile: String (R/W)

Saves the bitmap that appears on the speed button to a file.

Property Property NumGlyph: Integer (R/W)

Set NumGlyphs to the number of images provided by the bitmap assigned to the Glyph property. All images must be the same size and next to each other in a row. The Glyph property can provide up to four images.

Code Snippet

spdbtnSpeedButton1.Glyph.LoadFromFile("speedbutton.bmp")

spdbtnSpeedButton1.NumGlyphs = 2