User Tools

Site Tools


k16:k16.17:start

16.17 CheckBox

The next two chapters describe the two components CheckBox and RadioButton. Each component has its own specific function:

  • A CheckBox is a component for activating/deactivating an option.
  • A RadioButton, on the other hand, is a component for selecting an option from a group of at least 2 options. Each option is represented by a radio button of the group and only one option can be selected.

Beispiel

Figure 16.17.1: Three CheckBoxes and a group of three RadioButtons

  • For example, for the scanner → figure 16.17.1, you set with three checkboxes 8 completely independent of each other existing variants - from all three options ☑☑☑ set to no option ⎕⎕⎕ set.
  • For the scan mode, you can use three RadioButtons to select only one mode from three possible modes, since all three RadioButtons belong to the same group and only one RadioButton can be set to active.

Control element CheckBox

The control element CheckBox (gb.qt4) implements a CheckBox that can be selected or not. If the tristate property is defined, then the CheckBox state is interpreted as “state unknown (not defined)” or “should not be changed”.

tablelayout

PropertyTypeDefaultDescription
AutoresizeBooleanFalseDetermines the value or determines whether the size of the CheckBox automatically adapts to the descriptive text.
TextStringNullDetermines the text or specifies the text to be displayed on the CheckBox as caption.
CaptionStringNullSynonym for Text
TristateBooleanFalseDetermines or determines whether the CheckBox has a third state.
ValueInteger0Determines or determines which value the CheckBox has.

Table 16.17.1: Properties CheckBox

The property CheckBox.Value can have three values -1, 0 or 1, which applies to the state in connection with the defined CheckBox constants and the .Tristate property:

tablelayout

symbolConditionValueConstant
Selected-1CheckBox.True
Not selected0CheckBox.False
Indeterminate1CheckBox.None ( + CheckBox.Tristate = True)

Table 16.17.2: Values of the property CheckBox.Value

The click event is triggered when the user clicks on the checkbox and the state of the checkbox changes. If CheckBox.Tristate = False, then the state changes alternatively. Otherwise, the order is:⎕ → ⊟ → ☑ .You can quickly convince yourself of this if you set the CheckBox.Tristate property to True or False for a CheckBox and use this event handling routine:

Public Sub CheckBox1_Click()
 
  Select CheckBox1.Value
    Case -1
      Print "CheckBox checked" 	    ' State: selected
    Case 0
      Print "CheckBox unchecked" 	    ' State: not selected
    Case CheckBox1.None
      Print "CheckBox indeterminate" ' State: indifferent
  End Select
 
End ' CheckBox1_Click()

This is remarkable: The complete source code (trunk/) of gambas show an application of CheckBox.Tristate only in the supplied example GameOfLife.

Download

Articles

Download


16.17 CheckBox

In den nächsten zwei Kapiteln werden die beiden Komponenten CheckBox und RadioButton beschrieben. Jede Komponente hat ihre spezifische Funktion:

  • Eine CheckBox ist eine Komponente zum Aktivieren/Deaktivieren einer Option.
  • Ein RadioButton dagegen ist eine Komponente zur Auswahl einer Option aus einer Gruppe von mindestens 2 Optionen. Jede Option wird durch einen RadioButton der Gruppe repräsentiert. und es kann nur genau eine Option ausgewählt werden.

Beispiel

Abbildung 16.17.1: Drei CheckBoxen und eine Gruppe von drei RadioButton

  • Für den Scanner → Abbildung 16.17.1 setzen Sie zum Beispiel mit drei CheckBoxen 8 völlig unabhängig voneinander existierende Varianten – von alle drei Optionen ☑☑☑ gesetzt bis keine Option ⎕⎕⎕ gesetzt.
  • Für den Scan-Modus können Sie mit drei RadioButton nur einen Modus aus drei möglichen Modi auswählen, da alle drei RadioButton zur gleichen Gruppe gehören und nur ein RadioButton aktiv gesetzt werden kann.

Komponente CheckBox

Die Komponente CheckBox (gb.qt4) implementiert eine CheckBox, die markiert werden kann oder nicht. Wenn die Tristate-Eigenschaft festgelegt ist, dann wird der CheckBox-Zustand im Sinne von “Zustand unbekannt (nicht definiert)” oder “soll nicht geändert werden” interpretiert.

EigenschaftTypDefaultBeschreibung
AutoresizeBooleanFalseErmittelt den Wert oder legt fest, ob sich die Größe der CheckBox automatisch an den beschreibenden Text anpasst.
TextStringNullErmittelt den Text oder legt den Text fest, der auf der CheckBox als Beschriftung angezeigt wird.
CaptionStringNullSynonym für Text
TristateBooleanFalseErmittelt oder legt fest, ob die CheckBox über einen dritten Zustand verfügt.
ValueInteger0Ermittelt oder legt fest, welchen Wert die CheckBox hat.

Tabelle 16.17.1: Eigenschaften CheckBox

Die Eigenschaft CheckBox.Value kann drei Werte annehmen -1, 0 oder 1. Dabei gilt für den Zustand im Zusammenhang mit den definierten CheckBox-Konstanten und der .Tristate-Eigenschaft:

SymbolZustandWertKonstante
Ausgewählt-1CheckBox.True
Nicht ausgewählt0CheckBox.False
Unbestimmt1CheckBox.None ( + CheckBox.Tristate = True)

Tabelle 16.17.2: Werte der Eigenschaft CheckBox.Value

Das Klick-Ereignis wird ausgelöst, wenn der Benutzer auf die CheckBox klickt und es ändert sich der Zustand der CheckBox. Gilt CheckBox.Tristate = False, dann ändert sich der Zustand alternativ. Sonst gilt die Reihenfolge: ⎕ → ⊟ → ☑ ! Davon können Sie sich selbst schnell überzeugen, wenn Sie für eine CheckBox die Eigenschaft CheckBox.Tristate auf True oder False setzen und diese Ereignisbehandlungsroutine einsetzen:

Public Sub CheckBox1_Click()
 
  Select CheckBox1.Value
    Case -1
      Print "CheckBox checked" 		' Zustand: ausgewählt
    Case 0
      Print "CheckBox unchecked" 	' Zustand: nicht ausgewählt
    Case CheckBox1.None
      Print "CheckBox indeterminate" 	' Zustand: indifferent
  End Select
 
End ' CheckBox1_Click()

Das ist schon bemerkenswert: Die gesamten Quelltexte (trunk/) von Gambas zeigen nur im mitgelieferten Beispiel GameOfLife eine Anwendung von CheckBox.Tristate.

Download

Artikel

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.
k16/k16.17/start.txt · Last modified: 02.07.2018 (external edit)

Page Tools