The unobtrusive DirBox (gb.form) control implements a directory selection box:
Figure 6.9.1.1: DirBox control with other controls (FileView and FileProperties)
The selection dialogue for a directory is started by clicking on the directory symbol at the right end of the text field of the DirBox - marked in red:
Figure 6.9.1.2: Selection dialogue with selected directory “DBAdressen”.
The selected directory is taken over with “Select”. The directory path is then in the text field of the directory selection box. The text field has the property “ReadOnly”. The control element can be created:
Dim hDirBox As DirBox hDirBox = New DirBox ( Parent As Container ) As "EventName"
The DirBox class has these two properties, among others:
Property | Data type | Description |
---|---|---|
Border | Boolean | Indicates whether a border is set (default) or removes an existing border with the value 'False'. |
Value | String | Returns the path to the selected directory or sets the (start) directory in the source code. If you do not specify a start directory, the home directory is automatically preset. |
Table 6.9.1.1 : Properties of the DirBox class
The DirBox class has these events, among others:
Event | Description |
---|---|
Click() | This event is triggered when a user has selected a directory. The path to the selected directory is in the text field (property “ReadOnly”) of the DirBox. |
Change() | This event is synonymous with the Click event. |
Table 6.9.1.2.1 : Events of the DirBox class
You can read the value of the DirBox.Value property and store it in a variable sDirPath, for example.
' Gambas class file Public sDirPath As String Public Sub Form_Open() FMain.Resizable = False DirBox1.Value = User.Home ' (Start-)Folder sDirPath = DirBox1.Value lblDirPath.Text = DirBox1.Value FileView1.Dir = DirBox1.Value FileView1.ShowPreview = True FileView1.ShowHidden = True FileView1.Background = &HC3DDFF FileView1.Foreground = Color.Red FileView1.Mode = Select.Single FileView1.Filter = ["*.txt", "*.png", "*.pd*", "*.jp*", "*.xml"] FileView1.IconSize = 48 ' Default-Value = 32 FileProperties1.Path = DirBox1.Value End Public Sub DirBox1_Change() sDirPath = DirBox1.Value FileView1.Dir = DirBox1.Value lblDirPath.Text = DirBox1.Value End Public Sub FileView1_Click() FileProperties1.Path = sDirPath &/ FileView1.Current End
Controls of the Dialog class (gb.qt4) for selecting files or directories such as OpenFile or SelectDirectory or SaveFile for saving files are described in Chapter 12.
Project