Export (0) Print
Expand All
A
Expand Minimize

Visual Basic: Windows Controls

Visual Studio 6.0

Add Method (Panels Collection)

See Also    Example    Applies To

Adds a Panel object to a Panels collection and returns a reference to the newly created Panel object.

Syntax

object.Add(index, key, text, style, picture)

The Add method syntax has these parts:

Part Description
object An object expression that evaluates to a Panels collection.
index Optional. An integer specifying the position where the Panel object is to be inserted. If no index is specified, the Panel is added to the end of the Panels collection.
key Optional. A unique string that identifies the Panel. Use key to retrieve a specific Panel. This is equivalent to setting the Key property of the new Panel object after the object has been added.
text Optional. A string that appears in the Panel. This is equivalent to setting the Text property of the new Panel object after the object has been added.
style Optional. The style of the panel. The available styles are detailed in the Style Property (Panel Object). This is equivalent to setting the Style property of the new Panel object after the object has been added.
picture Optional. Specifies the bitmap displayed in the active Panel. For more information, see the LoadPicture function. This is equivalent to setting the Picture property of the new Panel object after the object has been added.

Remarks

At run time, the Add method returns a reference to the newly inserted Panel object. With this reference, you can set properties for every new Panel in the following manner:

Dim pnlX As Panel
Dim i As Integer
For i = 1 To 6  ' Add six Panel objects.
  ' Create a panel and get a reference to it simultaneously.
  Set pnlX = StatusBar1.Panels.Add(, "Panel" & i) ' Set Key property.
  pnlX.Style = i  ' Set Style property.
  pnlX.AutoSize = sbrContents ' Set AutoSize property.
Next i

The value of the Text property is displayed in a Panel object when the Panel object's Style property is set to sbrText.

The Panels collection is a 1-based collection. In order to get a reference to the first (default) Panel in a collection, you can use its Index or Key (if there is one) properties, or the Item method. The following code references the first Panel object using its index.

Dim pnlX As Panel
' Get a reference to first Panel.
Set pnlX = StatusBar1.Panels(1) ' Use the index
pnlX.Text = "Changed text"   ' Alter the Panel object's text.

By default, one Panel already exists on the control. Therefore, after adding panels to a collection, the Count will be one more than the number of panels added. For example:

Dim i as Integer
For i = 1 to 4  ' Add four panels.
   StatusBar1.Panels.Add ' Add panels without any properties.
Next i
MsgBox StatusBar1.Panels.Count ' Returns 5 panels.
Show:
© 2014 Microsoft