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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
''' <summary>
''' Deaktiviert alle Eingabefelder der Form
''' </summary>
''' <param name="ParentForm"></param>
''' <param name="Enabled"></param>
''' <remarks></remarks>
Public Sub DisableForm(ByRef ParentForm As System.Windows.Forms.Form, Optional ByVal Enabled As Boolean = False)
Dim Controls() As String = {"TextBox", "ListBox", "ComboBox", "Button"}
Dim L As New List(Of Control)
For Each CtrlType As String In Controls
If GetControls(ParentForm, CtrlType, L) = True Then
For Each ctl As Control In L
ctl.Enabled = Enabled
Next
End If
Next
End Sub
''' <summary>
''' Aktiviert alle Eingabefelder der Form
''' </summary>
''' <param name="frm"></param>
''' <remarks></remarks>
Public Sub EnableForm(ByRef frm As System.Windows.Forms.Form)
DisableForm(frm, True)
End Sub
''' <summary>
''' Sammelt alle Controls, deren Bezeichnung dem gegebenen Key entsprechen
''' </summary>
''' <param name="BaseControl">Parent, in dem gesucht werden soll</param>
''' <param name="Key">Bezeichnung, Teil der Bezeichnung</param>
''' <param name="L"></param>
''' <param name="Recursive"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function GetControls(ByVal BaseControl As Control, ByVal Key As String, ByRef L As List(Of Control), Optional ByVal Recursive As Boolean = True) As Boolean
If L Is Nothing Then L = New List(Of Control)
Dim InsertThisControl As Boolean
Dim ReturnFlag As Boolean = False
Key = Key.ToLower
'Alle Children durchlaufen
If BaseControl.HasChildren = True Then
For Each ctl As Control In BaseControl.Controls
InsertThisControl = False
If Key Is Nothing Then
'Alle einfügen
InsertThisControl = True
Else
'Key-Bezeichnung im Control-Namen enthalten?
If InStr(ctl.Name.ToLower, Key) > 0 Then
InsertThisControl = True
End If
End If
If InsertThisControl = True Then L.Add(ctl)
If Recursive = True Then
'Alle untergeordneten durchlaufen
Call GetControls(ctl, Key, L)
End If
Next
End If
If L.Count > 0 Then Return True
Return False
End Function
|