When the layout for a programme interface is static, if the window size is too small, you get into the situation where some components are no longer fully visible and others are completely invisible. A way out of this is to use a ScrollView that is placed on the form with the Form.Arrangement property set to Arrange.Fill. Now you can safely reach all the components using the scrollbars.
The ScrollView class implements a container in which you can scroll through its contents. Scroll bars are automatically displayed when components in the ScrollView are not visible or only partially visible.
Property | Data type | Default | Description |
---|---|---|---|
Arrangement | Integer | 0 | Determines or sets how the components should be arranged in the scrollview. In the class Arrange → Chapter 20.7.2 you will find a list of constants for this property. |
Border | Integer | 0 | Sets the type of border to be displayed or returns this type. See the Border class → Chapter 23.2.1 for a list of constants for this property. |
Indent | Boolean | False | If true, the first element is indented. The indent depth is Desktop.Scale (pixels). The direction is determined by the value of .Invert. |
Invert | Boolean | False | If true, then the content in the container is not arranged from left to right but the other way round. |
Margin | Boolean | False | If true, then a space is inserted between the container margin and the elements in the container. This space is Desktop.Scale (Pixel). |
Padding | Integer | 0 | A space of k pixels is inserted between the container border and the elements in the container. |
Spacing | Boolean | False | If true, a (horizontal) space is inserted between the elements in the container. This spacing is Desktop.Scale (Pixel). |
Scrollbar | Integer | 0 | Use the constants None (0), Horizontal (1), Vertical (2) and Both (3) to specify whether none, one or two scrollbars should be displayed. You can also read out the number and type of scroll bars displayed. |
ScrollX | Integer | 0 | Reads out or sets the horizontal scroll position. |
ScrollY | Integer | 0 | Reads out or sets the vertical scroll position. |
Table 18.10.1.1: Overview of ScrollView properties
Use the following 2 special methods of a ScrollView to control the visible areas in a ScrollView:
The ScrollView has only one specific event:
The ScrollView_Scroll( ) event is fired when scrolling through the contents of the ScrollView.
One use for a ScrollView in the project presented is a form to which components are added dynamically, and the number of these components can change constantly at programme runtime. In the project, the content of a database table (MySQL, PostgreSQL or SQLite3) is read out and displayed.
For each field of the table schema of the database table selected in a dialogue, a component pair (label,DB component) is created in a ScrollView. Internally, each component pair is bound to the components DataSource and DataBrowser, so that the field contents can also be edited! The label displays the field name. For the field types Boolean and Date, ComboBoxes and DateBoxes respectively are provided as DataControl. The data is thus entered in a controlled manner. For the other types, Gambas automatically performs a check - depending on the database data type.
Figure 18.10.4.1: Universal DB Manager
In Figure 18.10.4.1 you can see how you can scroll through the table on the one hand and also through the contents of the ScrollView on the other. The procedure in which the above-mentioned component pairs are generated in the ScrollView (svwControl) now becomes the focus of our considerations:
Private Sub GenerateControls() Dim hField As Field Dim hLabel As Label Dim hControl As DataControl For Each hField In $hConn.Tables[srcData.Table].Fields ' LABEL hLabel = New Label(svwControl) hLabel.Text = hField.Name hLabel.Move(0, 0, 100, 24) ' DB-COMPONENT hControl = New DataControl(svwControl) hControl.Move(100, 0, 100, 24) hControl.Expand = True hControl.Field = hField.Name Next svwControl.Visible = True End
The complete project of the universal database manager by Tobias Boege can be found in the download area. It contains in the folder DBMuster an SQLite3 database Kontakte.sqlite, whose database table kontakt you can use when testing the universal DB manager.