|
|
Title | Remove all Label controls from a form at run time in Visual Basic .NET |
Description | This example shows how to remove all Label controls from a form at run time in Visual Basic .NET. |
Keywords | remove controls, remove labels, label control, form, unload, VB.NET |
Categories | Controls, VB.NET |
|
|
When you click its button, the program loops through the form's controls from the last to the first. When it finds a Label control, it removes it from the form.
|
|
For i As Integer = Me.Controls.Count - 1 To 0 Step -1
If TypeOf Me.Controls(i) Is Label Then
Me.Controls.RemoveAt(i)
End If
Next
|
|
Note that looping through the controls with a For Each loop doesn't work (try it). Also looping through the controls from first to last makes the indexing very confusing.
|
|
|
|
|
|