This class implements a button - a button. A button can display a text, an image or both:
Figure 16.3.1: Three buttons in the GeoMap → project Chapter 17.15.1
Property | Data type | Default | Description |
---|---|---|---|
AutoResize | Boolean | False | Specifies whether the size of the button automatically adapts to the text. |
Caption | String | Null | Synonym for Text. |
Text | String | Null | Sets the text to be displayed on the button or returns it to. |
Value | Boolean | False | If the value is set to True, the button is activated - the click event is simulated. |
Picture | Picture | Null | Sets the image to be displayed on the button or returns this image. |
Tag | Variant | Null | Sets the property or reads the value. The Tag property can be used to store user-specific information in an object. |
ToolTip | String | Null | Sets the tooltip text to be displayed or returns it to the tooltip text of the button. |
Table 16.3.1.1: Selected button properties
For a button, the click event is the dominant event. It is triggered when the user clicks on the button with the mouse.
' This function returns the names of the classes with the required property in a matrix. Private Function SearchClasses(sProperty As String) As String[] Dim hClass As Class Dim aNamesMatrix As New String[] For Each hClass In Classes If hClass.Symbols.Exist(sProperty, gb.IgnoreCase) Then aNamesMatrix.Add(hClass.Name) Next Return aNamesMatrix.Sort() ' Return of the sorted array of names End ' Function SearchClasses(..) Public Sub btnAnzeigeLast_Click() Dim sElement As String TextArea.Clear For Each sElement In SearchClasses("PopupMenu") TextArea.Insert(sElement & ", ") Next End ' btnAnzeigeLast_Click()
Extensions exist if the properties Button. Default, Button. Cancel or Button. Value are set to the value True? properties.
Example 1 shows a button with which three different actions (start, stop and reset) can be triggered. The pivotal point here is the use of the tag property. A process is started and the time duration in seconds is displayed hexadecimal. After stopping, the time can be read off and finally the start state can be set with reset:
Figure 16.3.3.1: Short-time measurement with hexadecimal display
The source code contains only the relevant sections of a larger project:
[1] ... [2] [3] Private sSecond As Integer [4] [5] Public Sub Form_Open() [6] ... [7] [8] btnStartStop.Tag = "start" [9] btnStartStop.Picture = Picture["icon:/16/play"] [10] btnStartStop.Caption = " Starten" [11] Timer1.Delay = 1000 [12] LCDNumber1.Mode = 2 ' Hexadecimal [13] [14] ... [15] End ' Form_Open() [16] [17] Public Sub btnStartStop_Click() [18] [19] Select Case btnStartStop.Tag [20] Case "start" [21] btnStartStop.Picture = Picture["icon:/16/stop"] [22] btnStartStop.Tag = "stop" [23] btnStartStop.Caption = " Stoppen" [24] Timer1.Start ' Aktion starten [25] Case "stop" [26] btnStartStop.Picture = Picture["icon:/16/redo"] [27] btnStartStop.Tag = "reset" [28] btnStartStop.Caption = " Reset" [29] Timer1.Stop ' Aktion stoppen [30] Case "reset" [31] btnStartStop.Picture = Picture["icon:/16/play"] [32] btnStartStop.Tag = "start" [33] btnStartStop.Caption = " Starten" [34] sSecond = 0 [35] LCDNumber1.Value = 0 [36] End Select ' btnStartStop.Tag [37] [38] End ' btnStartStop_Click() [39] [40] Public Sub Timer1_Timer() [41] [42] Inc sSecond [43] LCDNumber1.Value = sSecond [44] [45] End ' Timer1_Timer()
Example 2 shows the project to demonstrate the component gb. map for displaying maps from openstreetmap. org. However, the focus is not on the display of the maps, but rather the use of properties, methods and the click event for the three buttons on the form Figure 16.3.4.2.
From the source code (complete) only lines 1 to 33 are relevant for the topic button. The source code is then commented:
[1] ' Gambas class file [2] [3] Public Sub Form_Open() [4] FMain.Center [5] FMain.Caption = "GeoMap - Daten von OpenStreetMap ©" [6] [7] btnShowMap.Picture = Picture["icon:/16/internet"] [8] btnShowMap.Text = " Anzeige GeoMap" [9] btnShowMap.Default = True [10] btnShowMap.SetFocus [11] [12] btnClose.Caption = "&Beenden" [13] [14] btnShowHelp.Text = Null [15] btnShowHelp.Tooltip = "Hinweise zur Nutzung von GeoMap" [16] btnShowHelp.Picture = Picture["icon:/16/help"] [17] [18] End ' Form_Open() [19] [20] Public Sub btnShowMap_Click() [21] If btnShowHelp.Tag = Null Then [22] btnShowHelp.Value = True [23] btnShowHelp.Tag = 1 [24] Endif ' btnHelp.Tag = Null ? [25] ShowMap() [26] End ' btnShowMap_Click() [27] [28] Public Sub btnShowHelp_Click() [29] HelpMessage() [30] End ' btnShowHelp_Click() [31] [32] Public Sub btnClose_Click() [33] FMain.Close [34] End ' btnClose_Click() [35] [36] '************************************************************************ [37] Private Sub ShowMap() [38] Dim iZoom As Integer [39] Dim fLatitude, fLongitude As Float [40] Dim sCacheName, sTileName, sTilePattern As String [41] Dim cArguments As New Collection [42] [43] iZoom = 13 [44] fLatitude = 52.78631 ' °Breite Osterburg [45] fLongitude = 11.73872 ' °Länge Osterburg [46] sTileName = "OpenStreetMap" [47] sTilePattern = "85.30.190.241/{z}/{x}/{y}.png" [48] cArguments = Null [49] sCacheName = Null [50] MapView1.Map.AddTile(sTileName, sTilePattern, cArguments, sCacheName) [51] MapView1.AllowEffect = False [52] MapView1.Map[sTileName].Visible = True [53] MapView1.Map.Center = MapPoint(fLatitude, fLongitude) [54] MapView1.Map.Zoom = iZoom [55] [56] End ' ShowMap [57] [58] Private Sub HelpMessage() [59] Dim sMessage As String [60] [61] sMessage = "<hr><b>Hinweise zum Einsatz der Komponente Map</b><hr>" [62] sMessage &= "» Verschieben der Karte mit der linken Maustaste" [63] sMessage &= "<br>» Zoomen mit dem Maus-Rad>" [64] sMessage &= "<br>» Original-Zoom mit 'Anzeige GeoMap'<hr>" [65] sMessage &= "» Enter-Taste setzt Standard-Anzeige (Original-Zoom)" [66] sMessage &= "<br>» Tastenkombination ALT+b beendet das Programm<hr>" [67] sMessage &= "▪ Entwickler der Komponente gb.map ist Fabien Bodard" [68] sMessage &= "<br>▪ EMail: gambix@users.sourceforge.net<hr>" [69] Message.Info(sMessage) [70] End ' HelpMessage()
Comments:
Figure 16.3.4.1: Program help
Figure 16.3.4.2: Project GeoMap
Hint:
If the function is called with only one argument, then there is only the “OK” button.
Articles