Add, AddItem Method (StatusBar, Panels)

Purpose

Add a Panel object to a Panels collection.

Syntax

StatusBar.Add[Item] ([index], [key], [caption], [style], [picture])

StausBar.Panels.Add([index], [key], [caption], [style], [picture])

index, key, caption, style, image:Variant

Description

The StatusBar methods Add and AddItem, and the Panels.Add method, add or insert a Panel object to the Panels collection of the status bar.

index Optional. An integer specifying the position where you want to insert the Panel object. 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 object. Use this value to retrieve a specific Panel object.
caption Optional. A string that will appear in the Panel object.
style Optional. The style of the Panel object.
0 - Default. Text and/or a bitmap. Set text with the Text property. The Panel appears to be sunk into the status bar.
1 - Flat. The Panel displays no bevel, and text looks like it is displayed right on the status bar.
2 - Raised. The Panel appears to be raised above the status bar.
3 - Caps Lock key. Displays the letters CAPS in bold when Caps Lock is enabled, and dimmed when disabled.
4 - Number Lock. Displays the letters NUM in bold when the number lock key is enabled, and dimmed when disabled.
5 - Scroll Lock key. Displays the letters SCRL in bold when scroll lock is enabled, and dimmed when disabled.
6 - Insert key. Displays the letters INS in bold when the insert key is enabled, and dimmed when disabled.
7 - Date. Displays the current date and time in the system format or in the format specified in caption. The custom format used has to be the same as specified in Format().
image Optional. An integer or unique key that specifies a ListImage object in an associated ImageList control.

GFA-BASIC 32 omits the Style constants for a Panel, instead you could use the following Enum.

Example

' Constants for the StatusBar Panel Styles

Global Enum sbrText = 0, sbrFlat, sbrRaise, sbrCaps, sbrNum, sbrScroll, sbrIns, sbrDate

' Constants for Text alignment in StatusBar Panels

Global Enum sbrLeft = 0, sbrCenter, sbrRight

Ocx StatusBar sb

sb.Panels.Add , , "Part 1", sbrText

sb.Panels.Add , , "Part 2", sbrFlat

sb.Panels.Add , , "Part 3", sbrRaise

sb.Panels.Add , , "Caps", sbrCaps

sb.Panels.Add , , "Num", sbrNum

sb.Panels.Add , , "Scroll", sbrScroll

sb.Panels.Add , , "INS", sbrIns

sb.Panels.Add , , "c", sbrDate

Do : Sleep : Until Me Is Nothing

Remarks

GFA-BASIC 32 specific

Instead of explicitly using the Panels collection to access a Panel element, you can use a shorter notation. First, the StatusBar supports an Item property:

sb.Item(idx)sb.Panels.Item(idx)

Like the Item method of sb.Panels, Item is the default method of StatusBar. Therefore, a Panel can be accessed as follows:

sb(idx)sb.Panels(idx)

sb!idxsb.Panels!idx

Each dot saves about 30 bytes of code.

To enumerate over the Panels collection of a StatusBar Ocx, use For Each on the Ocx control directly, like:

Local p As Panel

For Each p In sb : DoSomething(p) : Next

Known Issues

The index property of Add[Item] works inconsistently: most of the time, it will do as desired, but sometimes the panel position will not be affected it by it and, on others, an 'Illegal Function Call' error is thrown.

The following example will throw the 'Illegal Function Call' error; this usually only happens if the index is the same as the panel number being created, below one or greater than the number of panels:

Ocx StatusBar sb

sb.AddItem , , "Panel 1"

sb.AddItem 2, , "Panel 2"

sb.AddItem , , "Panel 3"

Do : Sleep : Until Me Is Nothing

The following example, trying to set Panel 2 to be the first panel just does nothing...

Ocx StatusBar sb

sb.AddItem , , "Panel 1"

sb.AddItem 1, , "Panel 2"

sb.AddItem , , "Panel 3"

Do : Sleep : Until Me Is Nothing

...while this one setting Panel 3 to the first position does work.

Ocx StatusBar sb

sb.AddItem , , "Panel 1"

sb.AddItem , , "Panel 2"

sb.AddItem 1, , "Panel 3"

Do : Sleep : Until Me Is Nothing

There is no workaround for this and the best advice is to use caution when setting the index parameter.
[Reported by Jean-Marie Melanson, 26/02/2017]

See Also

StatusBar, Panels

{Created by Sjouke Hamstra; Last updated: 02/03/2017 by James Gaite}