![]() |
Tipp 0159
|
Alle Steuerelemente eines Formulars ermitteln
|
 |
|
Autor/Einsender: Datum: |
|
Michael Werner 26.03.2007 |
|
Entwicklungsumgebung: |
|
VB.Net 2005 |
Framework: |
|
2.0 |
|
|
Mit einer einfachen For Each-Schleife durch die Controls-Enumeration eines Formulars
|
|
|
For Each ctrl As Control In Me.Controls
|
|
|
werden die in sogenannten Container-Steuerelementen befindlichen Steuerelemente nicht mit erfasst. Zum Beispiel werden in einer
GroupBox oder einem Panel-Steuerelement häufig CheckBoxen oder RadioButtons
platziert und dort gruppiert.
Um auch diese Kindelemente von Container-Steuerelementen zu ermitteln, muss in einer Bedingungsschleife mit
|
|
|
If TypeOf Control Is GroupBox Then
|
|
|
der Container in einer weiteren Schleife durchlaufen werden.
|
|
|
For Each ctrl1 As Control In Me.Controls
MessageBox.Show(ctrl1.Name)
'Controls in GroupBox
If TypeOf ctrl1 Is GroupBox Then
For Each ctrl2 As Control In ctrl1.Controls
MessageBox.Show(ctrl2.Name)
Next
End If
'Controls in Panel
If TypeOf ctrl1 Is Panel Then
For Each ctrl2 As Control In ctrl1.Controls
MessageBox.Show(ctrl2.Name)
Next
End If
Next
|
|
|
|
|
Windows-Version |
98/SE |
 |
|
ME |
 |
|
NT |
 |
|
2000 |
 |
|
XP |
 |
|
Vista |
 |
|
Win
7 |
 |
|
|
|
Download (17,4 kB)
|
Downloads bisher: [ 273 ]
|
|
|