Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleRemove all Label controls from a form at run time in Visual Basic .NET
DescriptionThis example shows how to remove all Label controls from a form at run time in Visual Basic .NET.
Keywordsremove controls, remove labels, label control, form, unload, VB.NET
CategoriesControls, 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.
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated