User Tools

Site Tools


k18:k18.10:start

18.10 ScrollView

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.

18.10.1 Properties ScrollView

PropertyData typeDefaultDescription
Arrangement Integer0Determines 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.
BorderInteger0Sets 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.
IndentBooleanFalseIf true, the first element is indented. The indent depth is Desktop.Scale (pixels). The direction is determined by the value of .Invert.
InvertBooleanFalseIf true, then the content in the container is not arranged from left to right but the other way round.
MarginBooleanFalseIf true, then a space is inserted between the container margin and the elements in the container. This space is Desktop.Scale (Pixel).
PaddingInteger0A space of k pixels is inserted between the container border and the elements in the container.
SpacingBooleanFalseIf true, a (horizontal) space is inserted between the elements in the container. This spacing is Desktop.Scale (Pixel).
ScrollbarInteger0Use 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.
ScrollXInteger0Reads out or sets the horizontal scroll position.
ScrollYInteger0Reads out or sets the vertical scroll position.

Table 18.10.1.1: Overview of ScrollView properties

18.10.2 Methods ScrollView

Use the following 2 special methods of a ScrollView to control the visible areas in a ScrollView:

  • Scroll (X As Integer, Y As Integer) : Scrolls the content to the specified position in the ScrollView.
  • EnsureVisible (X As Integer, Y As Integer, Width As Integer, Height As Integer) : Ensures that a specified area of the ScrollView becomes visible.

18.10.3 Events ScrollView

The ScrollView has only one specific event:

The ScrollView_Scroll( ) event is fired when scrolling through the contents of the ScrollView.

18.10.4 Project Database Manager with 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.

Universeller_DBManager

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.

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.10/start.txt · Last modified: 07.10.2023 by emma

Page Tools