Nabend,
Ich würde gerne alle Controls meiner Form die der Benutzer ändern kann auflisten, auch wenn sie in anderen Containern verborgen sind.
Ich habe dafür folgenden Code entwickelt der allerdings leider keine Funktion aufweist.^^
Der sub wird im FormLoad Event aufgerufen.
Die Liste ist selbstverständlich deklariert.
Es tritt auch keine Fehlermeldung auf.
Ich würde gerne alle Controls meiner Form die der Benutzer ändern kann auflisten, auch wenn sie in anderen Containern verborgen sind.
Ich habe dafür folgenden Code entwickelt der allerdings leider keine Funktion aufweist.^^
VB.NET-Quellcode
- Private Sub ComandListe(ByVal Container As Object)
- If TypeOf Container Is Form Then
- Dim form As Form = DirectCast(Container, Form)
- For Each con As Control In form.Controls
- If TypeOf con Is Panel Then
- ComandListe(con)
- End If
- If TypeOf con Is GroupBox Then
- ComandListe(con)
- End If
- Next
- End If
- If TypeOf Container Is Panel Then
- Dim Panel As Panel = DirectCast(Container, Panel)
- For Each con As Control In Panel.Controls
- If TypeOf con Is Panel Then
- ComandListe(con)
- End If
- If TypeOf con Is GroupBox Then
- ComandListe(con)
- End If
- Next
- End If
- If TypeOf Container Is GroupBox Then
- Dim GpB As GroupBox = DirectCast(Container, GroupBox)
- For Each con As Control In GpB.Controls
- If TypeOf con Is Panel Then
- ComandListe(con)
- End If
- If TypeOf con Is GroupBox Then
- ComandListe(con)
- End If
- Next
- End If
- If TypeOf Container Is TextBox Then
- Dim Objekt As TextBox = DirectCast(Container, TextBox)
- ControlList.Add(Objekt)
- ComboBox1.Items.Add(Objekt.Name)
- End If
- If TypeOf Container Is ComboBox Then
- Dim Objekt As ComboBox = DirectCast(Container, ComboBox)
- ControlList.Add(Objekt)
- ComboBox1.Items.Add(Objekt.Name)
- End If
- If TypeOf Container Is CheckBox Then
- Dim Objekt As CheckBox = DirectCast(Container, CheckBox)
- ControlList.Add(Objekt)
- ComboBox1.Items.Add(Objekt.Name)
- End If
- If TypeOf Container Is RadioButton Then
- Dim Objekt As RadioButton = DirectCast(Container, RadioButton)
- ControlList.Add(Objekt)
- ComboBox1.Items.Add(Objekt.Name)
- End If
- If TypeOf Container Is NumericUpDown Then
- Dim Objekt As NumericUpDown = DirectCast(Container, NumericUpDown)
- ControlList.Add(Objekt)
- ComboBox1.Items.Add(Objekt.Name)
- End If
- End Sub
Der sub wird im FormLoad Event aufgerufen.
Die Liste ist selbstverständlich deklariert.
Es tritt auch keine Fehlermeldung auf.