User Tools

Site Tools


k18:k18.14:start

18.14 StatusBar

The StatusBar class by Raymond de Bruijne (http://gambas-club.de/viewtopic.php?f=4&t=2928) uses a panel as a container for a StatusBar at the bottom of the window (default setting), where labels can be inserted to display text. Each label can be formatted in a particular way - depending on the purpose of the display:

StatusBar

Figure 18.14.1: Container StatusBar with 4 labels

The special feature of the StatusBar is that the individual labels are clickable and thus further information - for example in a MessageBox - can be displayed:

B2

Figure 18.14.2: Information on label 3

In addition, for each label in the StatusBar (→ Figure 18.14.1) you can

  • to display a text (optional),
  • specify a custom writing and background colour for the text,
  • specify the alignment of the (optional) text and
  • assign the margin properties.

18.14.1 Properties StatusBar

The StatusBar class has only the one property Version (data type String, readonly), which allows you to retrieve the current version of the class.

18.14.2 Methods StatusBar

The methods of the StatusBar class are most easily accessed via the source code of the class:

[1] ' Gambas class file
[2]
[3] '******************************************************************************
[4] ' Klassenname: Statusbar.class
[5] ' Datum:       18.03.2011 - 4.11.2013
[6] ' Autor:       Raymond de Bruijne
[7] ' Anpassung:   Dr. Hans-Joachim Lehmann
[8] ' EMail:       rdbruijne@freenet.de, hans@gambas-buch.de
[9] '******************************************************************************
[10] ' Eigenschaften
[11] '******************************************************************************
[12] Property Read Version As String
[13]
[14] '******************************************************************************
[15] ' (Arbeits-)Variablen
[16] '******************************************************************************
[17] Private $Version As String = "0.1.2"       ' Versionsinformation
[18] Private $StatusbarHeight As Integer = 28   ' Statusbarhöhe
[19] Private $MenubarHeight As Integer = 24     ' Menübarhöhe
[20] Private $StatusBarContainer As Panel       ' Panel als Statusbar-Container
[21] Private $Count As Integer                  ' Zähler für Labels
[22] Private $Label[255] As Label               ' Maximal 255 Labels verfügbar
[23] Private $LabelWidth[255] As Integer        ' Speicher Label-Breite
[24] Private $LabelSpace As Integer = 3         ' Abstand zwischen den einzelne Labels
[25] Private $OffSet As Integer = 2             ' OffSet-Wert für Rahmen
[26]
[27] '******************************************************************************
[28] ' Methoden
[29] '******************************************************************************
[30] Private Function Version_Read() As String
[31]   Return $Version
[32] End ' Version_Read()
[33]
[34] Public Sub _new(Parent As Container, PanelWidth As Integer, Optional Text As String)
[35]
[36]   ' --------------------------------------------------------------------------
[37]   ' Statusbar-Container erzeugen
[38]   ' --------------------------------------------------------------------------
[39]   $StatusBarContainer = New Panel(Parent)
[40]   $StatusBarContainer.Border = Border.Sunken
[41]
[42]   ' --------------------------------------------------------------------------
[43]   ' 1. Label erzeugen
[44]   ' --------------------------------------------------------------------------
[45]   Inc $Count
[46]   $Label[1] = New Label($StatusBarContainer)
[47]   StatusBarInit($Count, Parent)
[48]   With $Label[1]
[49]     .Width = Parent.Width
[50]     .Border = Border.Sunken
[51]     .Background = Color.Background
[52]     .Width = PanelWidth
[53]     .Text = Text
[54]   End With
[55]   $LabelWidth[1] = PanelWidth
[56]   BuildStatusBar(Parent)
[57]
[58] End
[59]
[60] Private Sub BuildStatusBar(hParent As Container)
[61]
[62]   Dim $Counter As Integer
[63]   Dim $PositionX As Integer = $OffSet
[64]   Dim $RestFensterbreite As Integer
[65]
[66]   ' --------------------------------------------------------------------------
[67]   ' Statusbar
[68]   ' --------------------------------------------------------------------------
[69]   If hParent.Window.Menus.Count > 0 Then
[70]    ' Falls im Elternfenster ein Menüleiste vorhanden ist:
[71]      $StatusBarContainer.Move(0, hParent.H - ($StatusbarHeight + $MenubarHeight - $OffSet),
                            hParent.Width, 26)
[72]   Else
[73]    ' Das Gleiche ohne Menüleiste:
[74]      $StatusBarContainer.Move(0, hParent.H - $StatusbarHeight - $OffSet, hParent.Width, 26)
[75]   Endif
[76]
[77]   ' --------------------------------------------------------------------------
[78]   ' Label einfügen
[79]   ' --------------------------------------------------------------------------
[80]   If $Count = 1 Then
[81]    ' Bei nur einem Label die gesamte (verfügbare) Fensterbreite ausnutzen
[82]      $Label[1].Move($OffSet, $OffSet, hParent.Width - (2 * $OffSet), 22)
[83]   Else
[84]     ' Labels einfügen ...
[85]      For $Counter = 1 To $Count
[86]        If $Counter = 1 Then
[87]         ' Das erste Label an den Anfang setzen...
[88]           $Label[$Counter].Move($OffSet, $OffSet, $LabelWidth[$Counter] - (2 * $OffSet), 22)
[89]           $PositionX += $Label[$Counter].Width + $LabelSpace
[90]        Else
[91]          ' ...und anschliessend weitere Labels einfügen
[92]           $Label[$Counter].Move($PositionX, $OffSet, $LabelWidth[$Counter] - (2 * $OffSet), 22)
[93]          $PositionX += $Label[$Counter].Width + $LabelSpace
[94]        Endif ' $Counter = 1 ?
[95]       ' ...und zum Schluß bei mehr als einem Label das letzte auf Rest-Fensterbreite anpassen
[96]        If $Count = $Counter Then
[97]           $RestFensterbreite = hParent.Width - $Label[$Counter - 1].X - $Label[$Counter - 1].Width -
                             (2 * $OffSet)
[98]           $Label[$Counter].Width = $RestFensterbreite - $OffSet
[99]        Endif
[100]     Next
[101]   Endif
[102]
[103] End
[104]
[105] Public Sub Add(hParent As Container, Width As Integer, Optional Text As String)
[106]
[107]   Inc $Count
[108]   $Label[$Count] = New Label($StatusBarContainer)
[109]   With $Label[$Count]
[110]     .Width = Width
[111]     .Text = Text
[112]     .Border = Border.Sunken
[113]     .Background = Color.Background
[114]   End With
[115]   $LabelWidth[$Count] = Width
[116]   StatusBarInit($Count, hParent)
[117]   BuildStatusBar(hParent)
[118]
[119] End
[120]
[121] Private Sub StatusBarInit(Id As Integer, Parent As Container)
[122]   Object.Attach($Label[Id], Parent, "StatusLabel" & Id) '  Event-Name ist 'StatusLabel'
[123] End
[124]
[125] Public Sub Resize(hParent As Container)
[126]   BuildStatusBar(hParent)
[127] End
[128]
[129] Public Sub SetText(Id As Integer, Text As String)
[130]   $Label[Id].Text = Text
[131] End
[132]
[133] Public Sub SetBorder(Id As Integer, Border As Integer)
[134]   $Label[Id].Border = Border
[135] End
[136]
[137] Public Sub SetAlignment(Id As Integer, Alignment As Integer)
[138]   $Label[Id].Alignment = Alignment
[139] End
[140]
[141] Public Sub SetToolTip(Id As Integer, Text As String)
[142]   $Label[Id].ToolTip = Text
[143] End
[144]
[145] Public Sub SetBackground(hParent As Container, Label_Id As Integer, Value As Integer)
[146]   $Label[Label_Id].Background = Value
[147]   BuildStatusBar(hParent)
[148] End
[149]
[150] Public Sub SetForeground(hParent As Container, Label_Id As Integer, Value As Integer)
[151]   $Label[Label_Id].Foreground = Value
[152]   BuildStatusBar(hParent)
[153] End

18.14.3 Events StatusBar

You can generate a specific event for each label according to the following syntax, where the events correspond to those of a label. For all ID's, the event name is StatusLabel:

Public Sub Event-Name&Label-ID&_Ereignis
  … Ereignisbehandlungsroutine
End

Here is the specific implementation for the left mouse button click on the 3rd label, as there is no Click() event for a label:

' Ereignis auslösen - Label 3 - Einfachklick LMT
Public Sub StatusLabel3_MouseDown()
  If Mouse.Left Then Message.Info("StatusBar-Label 3 wurde einfach angeklickt")
End ' StatusLabel3_MouseDown()

What you display in the message box depends mainly on the programme context.

18.14.4 Project CLS VirenScanner

The project 'CLS VirenScanner' provides a GUI for the Avira command line scanner. The source code is given only in the excerpts necessary to understand the use of the StatusBar class:

' Gambas class file
 
Private myStatusbar As Statusbar
 
Public Sub Form_Open()
 
  FMain.Center
  Timer1.Delay = 1000
  Timer1.Start
 
  myStatusbar = New Statusbar(Me, 240, Format$(Now, "dddd, dd/mm/yyyy hh:nn:ss"))
  myStatusBar.SetBackground(Me, 1, &HFFFFDF)
  myStatusBar.SetForeground(Me, 1, &H000000)
  myStatusbar.SetToolTip(1, "Datum&Zeit")
  myStatusbar.SetAlignment(1, Align.Center)
 
  myStatusbar.Add(Me, 100, "Not Running")
  myStatusBar.SetBackground(Me, 2, &HFFFFDF)
  myStatusBar.SetForeground(Me, 2, Color.Red)
  myStatusbar.SetToolTip(2, "Programm-Status")
  myStatusbar.SetAlignment(2, Align.Center)
 
  myStatusbar.Add(Me, 210, "Version VDF = 23.5.66.8")
  myStatusBar.SetBackground(Me, 3, &HEFFFDF)
  myStatusbar.SetAlignment(3, Align.Center)
 
' Die Feldlänge wird beim letzten Feld automatisch gesetzt -> 0 eintragen!
  myStatusbar.Add(Me, 0, "StatusBar-Version = " & myStatusbar.Version)
  myStatusBar.SetBackground(Me, 4, &HEFFFDF)
' myStatusbar.SetBorder(4, Border.Plain)
  myStatusbar.SetAlignment(4, Align.Center)
 
  FileView1.ShowDetailed = True
  lblDirectory.Text = DirView1.Current
 
End ' Form_Open()
 
'**********************************************************************
 
' Text setzen - Label 1
Public Sub Timer1_Timer()
  myStatusbar.SetText(1, Format$(Now, "dddd, dd/mm/yyyy hh:nn:ss"))
End ' Timer1_Timer() : Aktuelle Zeit im Panel 1 anzeigen
 
' Methode aufrufen
Public Sub Form_Resize()
  myStatusBar.Resize(Me)
End ' Form_Resize()
 
' Ereignis auslösen - Label 1 - Doppelklick
Public Sub StatusLabel1_DblClick()
  Message("StatusBar-Label 1 wurde doppelt angeklickt!")
End ' StatusPanel1_DblClick()
 
' Ereignis auslösen - Label 3 - Einfachklick LMT
Public Sub StatusLabel3_MouseDown()
  If Mouse.Left Then Message.Info("StatusBar-Label 3 wurde einfach angeklickt")
End ' StatusPanel3_MouseDown()
 
'**********************************************************************
'... Quelltext GUI Scanner - Ausschnitt
 
Public Sub DirView1_Select()
  FileView1.Dir = DirView1.Current
  lblDirectory.Text = DirView1.Current
  lblFile.Text = ""
End ' DirView1_Select()
 
Public Sub FileView1_Click()
  lblFile.Text = DirView1.Current &/ FileView1.Current
End ' FileView1_Click()
 
Public Sub btnClose_Click()
  FMain.Close
End ' btnClose_Click()

CLS

Figure 18.14.4.1: CLS Avira-AVGuard

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k18/k18.14/start.txt · Last modified: 07.10.2023 by emma

Page Tools