Visual Basic: Windows Controls

Button Object

See Also    Example    Properties    Methods    Events

A Button object represents an individual button in the Buttons collection of a Toolbar control.

Remarks

For each Button object, you can add text or a bitmap image, or both, from an ImageList control, and set properties to change its state and style.

At design time, use the Insert Button and Remove Button buttons on the Buttons tab in the Properties Page of the Toolbar control to insert and remove Button objects from the Buttons collection. At run time, you can also add Button objects by using the Add method of the Buttons collection.

At design time and run time, you can set the Caption, Image, Value, MixedState, and ToolTipText properties to change the appearance of each Button object.

Whenever a button is clicked on the Toolbar control, the ButtonClick event is called with the selected Button object passed in as a parameter. To cause some action to occur when a button is clicked, use the Index or Key properties in a Select Case statement as in the following code:

Select Case Button.Key
  Case Is = "open" ' Open file.
  ' Add code to Open a file here
  Case Is = "save" ' Save file.
  ' Add code to Save a file here
  Case Else
  ' If any other button is pressed
End Select