Contents
Buttons  Sample Help

Sample Desciption: Buttons

Points of Interest

Sizing Buttons

Button Clicks

Moving Buttons

Hiding Buttons

Executing Commands

Control

Button

For Help on Help, Press F1


Sample Description: Buttons
Buttons

The purpose of the button sample is to demonstrate some of the more common properties, methods, and events associated with Button controls. In this sample you will learn how to move and resize buttons, capture and record buttons click events, hide and unhide buttons and use Envelop buttons to carry out application commands.


Sizing a Button
Sizing Buttons

Example (1) in the button sample demonstrates how a button can be resized and relocated when it is clicked upon. A Click event is assigned to the button that deincrements the Left and Top properities while incrementing the Width and Height size properties. If the button reaches a maximum size, it is automatically resized and relocated to its original size and location.

In this example, the Left, Top, Width, and Height properties are revised each time the button is clicked. An alternative to changing these four properites would be to use the button’s Move method.


Button Clicks

Example (2) in the button sample demonstrates how the button's Caption property can be automatically changed each time the button is clicked. A Click event is assigned to the button. The first time the button is clicked, a text string “I’ve been clicked (1) time.” is set to the button's Caption property.

Subsequent clicks to the button use the command Instr to search the contents of the Caption property to identify the locations of the left parenthesis “(“ and right paren “)”. The number between the parentheses is incremented as the Caption property is updated.


Moving Buttons

Example (3) in the button sample demonstrates how buttons can be moved to different locations on the screen when they are clicked upon. A Click event is assigned to the button. Each time the button is clicked, its current location is determined in a Select Case statement, and a new location is assigned by setting the button's Left property to a new value.


Hiding Buttons

Example (4) in the button sample demonstrates how buttons may be hidden and unhidden when they are clicked upon. A Click event is assigned to all three buttons. When one of the buttons is clicked, its Visible property is set to False while the Visible property of the other two buttons is set to True. In addition, a message label’s Caption is updated with a status message to indicate which button is hidden.


Invoking a Command
Executing Commands

Example (5) in the button sample demonstrates how a button's click event can invoke a command that causes a change to another control on the screen. A Click event is assigned to four different buttons. When one of the buttons is clicked, the FileName property of a Bitmap object is set to a corresponding file in the samples directory. When this is done, the bitmap file is automatically loaded into the Bitmap object.

On the sample form, an Image control for example (5) is shown to the right. The Image control's Picture property has been set to the Bitmap object. When the Bitmap object loads a new bitmap file, the Image control’s display is automatically updated and refreshed.