Clear Method (ActiveX Controls) Example

This example adds six Panel objects to a StatusBar control, creating a total of seven Panel objects. A click on the form clears all Panel objects when their number reaches seven. If the number of Panel objects is less than seven, each click on the form will add a new Panel object to the control until the number seven is once again reached. 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 clear all Panel objects 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
   Next I
End Sub

Private Sub Form_Click()
   ' If the Count of the collection is 7, then clear the collection. 
   ' Otherwise, add one Panel and use the collection's Count property
   ' to set its Style.
   If StatusBar1.Panels.Count = 7 Then 
      StatusBar1.Panels.Clear
   Else
      Dim pnlX As Panel
      Set pnlX = StatusBar1.Panels.Add( , , "simple", 0)
      ' The Style property is enumerated from 0 to 6. Use the Panels
      ' Count property -1 to set the Style property for the new Panel.
      ' Display all panels regardless of form width.
      pnlX.minwidth = TextWidth("simple")
      pnlX.AutoSize = sbrSpring
      pnlX.Style = Statusbar1.Panels.Count - 1
   End If
End Sub