The SpeedButton component was designed to be used on speedbars. It is different from the Button and BitBtn components in that it is not a windowed component. This means that a speed button cannot receive input focus and cannot be tabbed to. On the other hand, the SpeedButton component has several things in common with the BitBtn component. The way in which the Glyph property is handled by the SpeedButton component is exactly the same as with the BitBtn component, so I'm not going to go over that ground again. There are a couple major differences, though, so let's go over those.
By default, speed buttons are square and are 25x25 pixels. Your speed buttons may be any size you like and can contain text, although typically speed buttons do not contain text. There are some properties specific to speed buttons that you should be aware of, which I've broken down in the following sections.
Speed buttons can be grouped to make them behave like radio buttons (radio buttons are discussed later in the chapter in the section "Radio Buttons and Check Boxes"). When one button in the group is pressed, it stays down, and the button that was previously pressed pops up again. To group speed buttons, simply assign the same value to the GroupIndex property for all buttons in a group. (The default value of 0 indicates that the button is not part of any group.) To illustrate, do the following exercise:
When you run the program, click on several of the buttons. You will notice that only one button can be in the down state at one time. As you can see when you assign a nonzero value to GroupIndex, the speed buttons change their behavior. A speed button with a GroupIndex of 0 pops back up when you click it, whereas a speed button that is part of a group stays down when clicked.
By default, one button in the group must be down at all times. You can change that behavior by setting the AllowAllUp property to true. Doing this for one button automatically changes the AllowAllUp property for all other buttons in the group to true as well. Now you can have any one button in the group selected or no buttons at all.
Sometimes you want a speed button to act as a toggle button. A toggle button is used to turn an option on or off and is not part of a button group. To make an individual speed button a toggle button, assign a nonzero value to its GroupIndex property and set its AllowAllUp property to true. Be sure to set the GroupIndex property to a value not used by any other components on the form. When the user clicks the button, it stays down. When the button is clicked again, it pops back up.
The Down property, when read, returns true if the button is currently down and false if it is not. When written to, the Down property can be used to toggle a button as pressed or not pressed. Writing to the Down property has no effect unless the speed button is part of a group.
Was this article helpful?