This class implements a button for a ToolBar. A ToolButton can display an image, a text or both. In most cases, the text is dispensed with:
Figure 16.5.1: ToolButton and separators in a toolbar in the IDE
The properties of a ToolButton differ only slightly from the special properties of a' normal' button.
Property | Data type | Default | Description |
---|---|---|---|
AutoResize | Boolean | False | Specifies whether the size of the ToolButton automatically adapts to the content (text/icon) |
Action | String | Null | Sets the action string that is bound to the ToolButton or returns the string back |
Caption | String | Null | Synonym for the text property |
Text | String | Null | Sets the text to be displayed on the ToolButton or returns it back |
Toogle | Boolean | False | With the value True the ToolButton has the properties of a Schalters |
Value | Boolean | False | Sets the value of the ToolButton as a toggle button (locked or unlocked) or returns this value |
Picture | Picture | Null | Sets the image to be displayed on the ToolButton or returns the image |
ToolTip | String | Null | Sets or returns the ToolTipö text to be displayed |
Table 16.5.1.1: Selected button properties
You can use any icon on the button - it will be automatically stretched - provided that you only use ToolButton or MenuButton in the toolbar (ToolBar).
The click event is also the dominant event for a ToolButton. It is triggered when the user clicks with the mouse on the ToolButton or when the value of the. value property changes.
Section of a source code for a project in which 4 toolbuttons (→ Figure 16.5.3.1) are used:
[1] Public Sub tbImageOpen_Click() [2] ImageOpen() [3] mnu13Print.Enabled = True [4] tbPrint.Enabled = True [5] End ' tbOpen_Click() [6] [7] Public Sub tbImagePrint_Click() [8] ImageOpen() [9] mnu13Print.Enabled = True [10] tbPrint.Enabled = True [11] End ' tbOpen_Click() [12] [13] Public Sub tbHelp_Click() [14] FHelp.Show [15] End ' tbOpen_Click() [16] [17] Public Sub tbFormClose_Click() [18] FHelp.Close [19] FMain.Close [20] End ' tbOpen_Click()
A tried and tested project for the use of a ToolBar with some ToolButtons can be found in → chapter 12.5 ToolBar. There you will find the complete source code, which is commented on in the relevant passages.
Figure 16.5.3.1: ToolButton and separators in a toolbar
Another project is described in chapter 18.6 Toolbar in connection with the properties, methods and events of the container component ToolBar.
Diese Klasse implementiert einen Button für eine ToolBar. Ein ToolButton kann ein Bild, einen Text oder beides anzeigen. In den meisten Fällen wird auf den Text verzichtet:
Abbildung 16.5.1: ToolButton und Separatoren in einer Toolbar in der IDE
Die Eigenschaften eines ToolButton unterscheiden sich nur wenig von den speziellen Eigenschaften eines 'normalen' Buttons.
ToolButton | Datentyp | Default | Beschreibung |
---|---|---|---|
.AutoResize | Boolean | False | Gibt an, ob sich die Größe des ToolButtons automatisch an den Inhalt (Text / Icon) anpasst |
.Action | String | Null | Setzt den Action-String, der an den ToolButton gebunden ist oder gibt den String zurück |
.Caption | String | Null | Synonym für .Text |
.Text | String | Null | Setzt den anzuzeigenden Text auf dem ToolButton oder gibt diesen zurück |
.Toogle | Boolean | False | Mit dem Wert True besitzt der ToolButton die Eigenschaften eines Schalters |
.Value | Boolean | False | Setzt den Wert des ToolButton als ToggleButton (eingerastet oder nicht eingerastet) oder gibt diesen Wert zurück |
.Picture | Picture | Null | Setzt das anzuzeigende Bild auf dem ToolButton oder gibt das Bild zurück |
.ToolTip | String | Null | Setzt den anzuzeigenden ToolTipp-Text des ToolButtons oder gibt diesen zurück |
Tabelle 16.5.1.1: Ausgewählte Button-Eigenschaften
Sie können ein beliebiges Icon auf die Schaltfläche verwenden – es wird automatisch gestreckt werden – vorausgesetzt, dass Sie nur ToolButton oder MenuButton in der Symbolleiste (ToolBar) verwenden.
Auch bei einem ToolButton ist das Klick-Ereignis das dominante Ereignis. Es wird ausgelöst, wenn der Benutzer mit der Maus auf den ToolButton klickt oder wenn sich der Wert der Eigenschaft .Value ändert.
Ausschnitt aus einem Quelltext für ein Projekt, in dem 4 Toolbutton (→ Abbildung 16.5.3.1) verwendet werden:
[1] Public Sub tbImageOpen_Click() [2] ImageOpen() [3] mnu13Print.Enabled = True [4] tbPrint.Enabled = True [5] End ' tbOpen_Click() [6] [7] Public Sub tbImagePrint_Click() [8] ImageOpen() [9] mnu13Print.Enabled = True [10] tbPrint.Enabled = True [11] End ' tbOpen_Click() [12] [13] Public Sub tbHelp_Click() [14] FHelp.Show [15] End ' tbOpen_Click() [16] [17] Public Sub tbFormClose_Click() [18] FHelp.Close [19] FMain.Close [20] End ' tbOpen_Click()
Ein erprobtes Projekt für den Einsatz einer ToolBar mit einigen ToolButton finden Sie im Kapitel 12.5. ToolBar. Dort finden Sie den kompletten Quelltext, der in den relevanten Passagen kommentiert wird.
Abbildung 16.5.3.1: ToolButton und Separatoren in einer Toolbar
Ein weiteres Projekt wird im Kapitel 18.6 Toolbar im Zusammenhang mit den Eigenschaften, Methoden und Ereignissen der Container-Komponente ToolBar beschrieben.