Buttons are pretty basic parts of most forms and dialog boxes. With most Windows 95 compilers, you just drag and drop a button, and place some code in the click event.

No big deal. What could possibly go wrong ...

As usual, the on-line help for these compilers (particularly VisualBasic 6.0) is less than adequate.

Visual Basic 6.0


Caption Text displayed on the button face
Cancel When True, the click event executes when esc is pressed
Default When True, the click event executes when Enter is pressed
Index If not blank, then the button is part of a Control Array

It is possible for the caption to have multiple lines of text, but there is no way to align the text.

Screwed Up Buttons

All I wanted was 2 buttons of the same size. I made the mistake of using the standard Windows Copy and Paste to make a copy of a button. Then I re-named the new button so that I wouldn't have 2 objects with the same name.

When I compiled the program, I got

This program had compiled fine before, but now the following code would not compile. When I commented out this code and double clicked on the original button, the following template was produced. Obviously, trouble shooting this was non-trivial. It turns out that when the index property is not blank, the button is part of a Control Array which shares one name for several objects and uses the index property to identify specific objects in the array. As a result, the index parameter is required for all property references and event definitions. For example, the following references a property.

As expected, I get exactly the same crystal clear error message if I delete the value of the index property but leave the index parameter in the event definition.

When you place the cursor on a button's index property and press F1, the help refers to objects in a collection (a completely different concept). Following this thread leads to multiple dead ends.

MS Access 97

I want a button where you click it once and it goes down, then you click it again and it comes up. The Toggle button provides this except that it won't stay down if the form is set to not allow edits. In addition, while code attached to the On Mouse Down event operates just fine, code attached to the On Click event is never called. The solution is to tell the form to allow edits and then Lock each field to prevent edits.

Supposedly, LabelAlign is supposed to allow the control of formatting on Command Buttons ... except that the property is not available on any of the buttons. Thus, center is the only "option".

(Placed here because MS Access is based on VB.)



Caption   The displayed text. It is not possible to have multiple lines of text or to change the default text alignment.
Enabled Disables and grays out the control.
Checked Applies to TCheckBox and TRadioButton.
AllowGrayed   Applies to TCheckBox. The State can be Checked, Unchecked, or Grayed Controls whether the user can generate a grayed state. Your program can do whatever.

TButton Parameters

Caption Text displayed on the button face
Cancel When True, the OnClick event handler executes when esc is pressed
Default When True, the OnClick event handler executes when Enter is pressed
ModalResult   When not zero, closes a modal dialog box


To place arrows on the buttons, you could use graphics (bitmaps). I use fonts. Specifically, Marlett is the font used by windows to provide the arrows used on scroll bars. The numbers 3, 4, 5, 6 represent the arrows.

Name Marlett  
Caption 3


Since there is no help with Delphi 5.0, a few comments may help.

I had a situation where 3 Spin Buttons were associated with 3 edit controls. Rather than have 6 routines to handle these, I set each FocusControl property to the associated edit control and used code similar to this.

This allowed all 3 up buttons to call one routine, and the down buttons to call the other.

C++ Builder

Author: Robert Clemenzi - clemenzi@cpcug.org
URL: http:// cpcug.org / user / clemenzi / technical / Languages / Buttons.htm