Hi Jabaco-Amigos
this one uses the TypeOf-Function, in order to enable/disable alle controls of a container in one single line.
Now there are two methods to reach this
* Container_SetControlsEnabled
* Component_SetEnabled
its usage is like:
|
Jabaco Source
|
1
2
3
4
5
6
7
8
9
10
11
|
Public Sub CheckBox1_Click()
'enables/disables all controls inside the splitpane
Container_SetControlsEnabled(SplitPane1, CBool(CheckBox1.Value))
End Sub
Public Sub CheckBox2_Click()
'enables/disables only the TextBox
Component_SetEnabled Text1, CBool(CheckBox2.Value)
' you could also try:
'TextBox1.Enabled = False
' but this line does not fulfill the whole job!
End Sub
|
here are the procedures:
- Component_SetEnabled:
|
Jabaco Source
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
Public Sub Component_SetEnabled(comp As java#awt#Component, _
bEnabled As Boolean)
'
' enabling_/disabling of one component depending on the
' type of the object
'
Select Case True
Case TypeOf(comp, "Frame")
Dim Fra As VB#Frame = Cast(comp, VB#Frame)
Fra.Parent.setEnabled(bEnabled)
Fra.SpecialEffect(fmSpecialEffectEtched)
Case TypeOf(comp, "ListBox")
Dim lbx As VB#ListBox = Cast(comp, ListBox)
lbx.Parent.setEnabled(bEnabled)
Case TypeOf(comp, "TextBox")
Dim tbx As VB#TextBox = Cast(comp, TextBox)
tbx.Enabled = bEnabled 'the text will stay copyable
'tbx.parent.setEnabled(bEnabled) 'even not copyable
tbx.parent.setEditable(bEnabled)
Case TypeOf(comp, "Label")
Dim lbl As VB#Label = Cast(comp, Label)
lbl.Enabled = bEnabled
'lbl.Parent.setEnabled(bEnabled)
lbl.Visible = True '??? why does it get invisible? no idea
lbl.Parent.setVisible(True)
Case TypeOf(comp, "TreeView")
Dim trv As VB#TreeView = Cast(comp, TreeView)
trv.Parent.setEnabled(bEnabled)
Case Else
comp.setEnabled(bEnabled)
End Select
End Sub
|
- Container_SetControlsEnabled:
|
Jabaco Source
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
Public Sub Container_SetControlsEnabled(cont As java#awt#Container, _
bEnabled As Boolean)
'
' enabling/disabling of all components on a container
' if one component is a container too, the method will
' be called recursively
'
' this is an extension for controls that can serve as a container
' for other controls e.g.: VB#Frame, VB#PictureBox etc.
'
Dim i As Integer, n As Integer
Dim comp As java#awt#Component
'enabling/disabling the container itself
'cont.setEnabled(bEnabled)
Component_SetEnabled(cont, bEnabled)
'enabling/disabling all containing components
n = cont.getComponentCount - 1
If n >= 0 Then
For i = 0 To n
comp = cont.getComponent(i)
If TypeOf(comp, "Container") Then
Dim conti As Container = Cast(comp, Container)
Container_SetControlsEnabled(conti, bEnabled)
Else
Component_SetEnabled(comp, bEnabled)
End If
Next
End If
End Sub
|
also have a look into the small example attached.
greetings
OlimilO