1. Home
  2. Computing & Technology
  3. Visual Basic

VB.NET: What Happened to Control Arrays!!! (Part 5)

By Dan Mabbutt, About.com

6 of 8

How Add works and the Delete subroutine

The Else clause on PBEmpty is only executed when the program starts up, mainly to prevent the other code from executing the first time.

When a new PictureBoxClass instance is created, it's saved in the array and then all of the properties, including the two new ones added to the inherited PictureBox class, are set. Then FlipPB is added as a Handler for the current element of the PB array - an instance of the class - and it's added to the controls collection of Me - which is Form1.

Here's the routine to delete.

~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub RemoveFromPB()
  If PB.Length > 0 Then
    Dim a As Integer = PB.Length - 1
    Dim temp(a) As PictureBoxClass
    PB.CopyTo(temp, 0)
    ReDim PB(a - 1)
    temp.Copy(temp, PB, a)
    Me.Controls.Remove(temp(a))
    temp(a).Dispose()
  End If
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~

Explore Visual Basic
By Category
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Using VB.NET
  5. How Add works and the Delete subroutine for Control Arrays

©2009 About.com, a part of The New York Times Company.

All rights reserved.