Get Labels from all Controls on a Form : Control « GUI « VB.Net






Get Labels from all Controls on a Form

Get Labels from all Controls on a Form
Imports System
Imports System.IO
Imports System.Windows.Forms

Public Class MainClass

   Shared Sub Main()
      Dim form1 As Form1 = new Form1()
      Application.Run(form1)
   End Sub 
End Class


Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For Each ctl As Control In Me.Controls
            If (ctl.Name.StartsWith("lbl")) AndAlso (TypeOf ctl Is Label) Then
                Dim lbl As Label = DirectCast(ctl, Label)
                lbl.Text = ""
            End If
        Next ctl
    End Sub

End Class


<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Public Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.lstDrives = New System.Windows.Forms.ListBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.lblAvailableFreeSpace = New System.Windows.Forms.Label
        Me.lblDriveFormat = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.lblIsReady = New System.Windows.Forms.Label
        Me.Label6 = New System.Windows.Forms.Label
        Me.lblDriveType = New System.Windows.Forms.Label
        Me.Label8 = New System.Windows.Forms.Label
        Me.lblVolumeLabel = New System.Windows.Forms.Label
        Me.Label10 = New System.Windows.Forms.Label
        Me.lblTotalFreeSpace = New System.Windows.Forms.Label
        Me.Label12 = New System.Windows.Forms.Label
        Me.lblRootDirectory = New System.Windows.Forms.Label
        Me.Label14 = New System.Windows.Forms.Label
        Me.lblName = New System.Windows.Forms.Label
        Me.Label16 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'lstDrives
        '
        Me.lstDrives.Dock = System.Windows.Forms.DockStyle.Left
        Me.lstDrives.FormattingEnabled = True
        Me.lstDrives.Location = New System.Drawing.Point(0, 0)
        Me.lstDrives.Name = "lstDrives"
        Me.lstDrives.Size = New System.Drawing.Size(136, 199)
        Me.lstDrives.TabIndex = 0
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(144, 152)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(104, 13)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "Available Free Space"
        '
        'lblAvailableFreeSpace
        '
        Me.lblAvailableFreeSpace.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblAvailableFreeSpace.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblAvailableFreeSpace.Location = New System.Drawing.Point(256, 152)
        Me.lblAvailableFreeSpace.Name = "lblAvailableFreeSpace"
        Me.lblAvailableFreeSpace.Size = New System.Drawing.Size(152, 16)
        Me.lblAvailableFreeSpace.TabIndex = 2
        '
        'lblDriveFormat
        '
        Me.lblDriveFormat.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblDriveFormat.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblDriveFormat.Location = New System.Drawing.Point(256, 128)
        Me.lblDriveFormat.Name = "lblDriveFormat"
        Me.lblDriveFormat.Size = New System.Drawing.Size(152, 16)
        Me.lblDriveFormat.TabIndex = 4
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(144, 128)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(63, 13)
        Me.Label4.TabIndex = 3
        Me.Label4.Text = "Drive Format"
        '
        'lblIsReady
        '
        Me.lblIsReady.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblIsReady.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblIsReady.Location = New System.Drawing.Point(256, 32)
        Me.lblIsReady.Name = "lblIsReady"
        Me.lblIsReady.Size = New System.Drawing.Size(152, 16)
        Me.lblIsReady.TabIndex = 8
        '
        'Label6
        '
        Me.Label6.AutoSize = True
        Me.Label6.Location = New System.Drawing.Point(144, 32)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(45, 13)
        Me.Label6.TabIndex = 7
        Me.Label6.Text = "Is Ready"
        '
        'lblDriveType
        '
        Me.lblDriveType.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblDriveType.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblDriveType.Location = New System.Drawing.Point(256, 56)
        Me.lblDriveType.Name = "lblDriveType"
        Me.lblDriveType.Size = New System.Drawing.Size(152, 16)
        Me.lblDriveType.TabIndex = 6
        '
        'Label8
        '
        Me.Label8.AutoSize = True
        Me.Label8.Location = New System.Drawing.Point(144, 56)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(55, 13)
        Me.Label8.TabIndex = 5
        Me.Label8.Text = "Drive Type"
        '
        'lblVolumeLabel
        '
        Me.lblVolumeLabel.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblVolumeLabel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblVolumeLabel.Location = New System.Drawing.Point(256, 104)
        Me.lblVolumeLabel.Name = "lblVolumeLabel"
        Me.lblVolumeLabel.Size = New System.Drawing.Size(152, 16)
        Me.lblVolumeLabel.TabIndex = 16
        '
        'Label10
        '
        Me.Label10.AutoSize = True
        Me.Label10.Location = New System.Drawing.Point(144, 104)
        Me.Label10.Name = "Label10"
        Me.Label10.Size = New System.Drawing.Size(67, 13)
        Me.Label10.TabIndex = 15
        Me.Label10.Text = "Volume Label"
        '
        'lblTotalFreeSpace
        '
        Me.lblTotalFreeSpace.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblTotalFreeSpace.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblTotalFreeSpace.Location = New System.Drawing.Point(256, 176)
        Me.lblTotalFreeSpace.Name = "lblTotalFreeSpace"
        Me.lblTotalFreeSpace.Size = New System.Drawing.Size(152, 16)
        Me.lblTotalFreeSpace.TabIndex = 14
        '
        'Label12
        '
        Me.Label12.AutoSize = True
        Me.Label12.Location = New System.Drawing.Point(144, 176)
        Me.Label12.Name = "Label12"
        Me.Label12.Size = New System.Drawing.Size(85, 13)
        Me.Label12.TabIndex = 13
        Me.Label12.Text = "Total Free Space"
        '
        'lblRootDirectory
        '
        Me.lblRootDirectory.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblRootDirectory.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblRootDirectory.Location = New System.Drawing.Point(256, 80)
        Me.lblRootDirectory.Name = "lblRootDirectory"
        Me.lblRootDirectory.Size = New System.Drawing.Size(152, 16)
        Me.lblRootDirectory.TabIndex = 12
        '
        'Label14
        '
        Me.Label14.AutoSize = True
        Me.Label14.Location = New System.Drawing.Point(144, 80)
        Me.Label14.Name = "Label14"
        Me.Label14.Size = New System.Drawing.Size(71, 13)
        Me.Label14.TabIndex = 11
        Me.Label14.Text = "Root Directory"
        '
        'lblName
        '
        Me.lblName.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblName.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblName.Location = New System.Drawing.Point(256, 8)
        Me.lblName.Name = "lblName"
        Me.lblName.Size = New System.Drawing.Size(152, 16)
        Me.lblName.TabIndex = 10
        '
        'Label16
        '
        Me.Label16.AutoSize = True
        Me.Label16.Location = New System.Drawing.Point(144, 8)
        Me.Label16.Name = "Label16"
        Me.Label16.Size = New System.Drawing.Size(31, 13)
        Me.Label16.TabIndex = 9
        Me.Label16.Text = "Name"
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(411, 200)
        Me.Controls.Add(Me.lblVolumeLabel)
        Me.Controls.Add(Me.Label10)
        Me.Controls.Add(Me.lblTotalFreeSpace)
        Me.Controls.Add(Me.Label12)
        Me.Controls.Add(Me.lblRootDirectory)
        Me.Controls.Add(Me.Label14)
        Me.Controls.Add(Me.lblName)
        Me.Controls.Add(Me.Label16)
        Me.Controls.Add(Me.lblIsReady)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.lblDriveType)
        Me.Controls.Add(Me.Label8)
        Me.Controls.Add(Me.lblDriveFormat)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.lblAvailableFreeSpace)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.lstDrives)
        Me.Name = "Form1"
        Me.Text = "GetDriveInfo"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents lstDrives As System.Windows.Forms.ListBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents lblAvailableFreeSpace As System.Windows.Forms.Label
    Friend WithEvents lblDriveFormat As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents lblIsReady As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents lblDriveType As System.Windows.Forms.Label
    Friend WithEvents Label8 As System.Windows.Forms.Label
    Friend WithEvents lblVolumeLabel As System.Windows.Forms.Label
    Friend WithEvents Label10 As System.Windows.Forms.Label
    Friend WithEvents lblTotalFreeSpace As System.Windows.Forms.Label
    Friend WithEvents Label12 As System.Windows.Forms.Label
    Friend WithEvents lblRootDirectory As System.Windows.Forms.Label
    Friend WithEvents Label14 As System.Windows.Forms.Label
    Friend WithEvents lblName As System.Windows.Forms.Label
    Friend WithEvents Label16 As System.Windows.Forms.Label

End Class

           
       








Related examples in the same category

1.Get Control Handle and check its valueGet Control Handle and check its value
2.Convert object to Control ObjectConvert object to Control Object
3.Control Paint DemoControl Paint Demo
4.Assign the Bitmap to the control's Image propertyAssign the Bitmap to the control's Image property
5.Component Client Rectangle and Display RectangleComponent Client Rectangle and Display Rectangle
6.Adding a control to a Form at run timeAdding a control to a Form at run time
7.Display Names for All controls on a FrameDisplay Names for All controls on a Frame