Remove Method (ActiveX Controls) Example

This example adds six Panel objects to a StatusBar control, creating a total of seven Panel objects. When you click on the form, the code checks to see how many Panel objects there are. If there is only one Panel object, the code adds six Panel objects. Otherwise, it removes the first panel. To try the example, place a StatusBar control on a form and paste the code into the Declarations section. Run the example and click on the form to remove one Panel object at a time, and subsequently add Panel objects.

Private Sub Form_Load()
   Dim pnlX As Panel  ' Declare object variable for Panel objects.
   Dim i As Integer

   ' Add 6 Panel objects to the single default Panel object,
   ' making 7 Panel objects.
   For i = 1 To 6
      Set pnlX = StatusBar1.Panels.Add(, , , i)
      pnlX.AutoSize = sbrSpring
   Next i
End Sub

Private Sub Form_Click()
   ' If the Count of the collection is 1, add 6 Panel objects.
   ' Otherwise, remove the first panel from the collection.
   If StatusBar1.Panels.Count = 1 Then
      Dim sbrX As Panel
      Dim i As Integer
      For i = 1 To 6 ' Each panel has its style set by i.
         Set sbrX = StatusBar1.Panels.Add(, , , i)
         sbrX.AutoSize = sbrSpring
      Next i
   Else ' Remove the first panel.
      StatusBar1.Panels.Remove 1
   End If
End Sub