Back to Devexpress

TdxCustomStatusBar.Panels Property

vcl-dxstatusbar-dot-tdxcustomstatusbar-7a223599.md

latest7.7 KB
Original Source

TdxCustomStatusBar.Panels Property

Provides access to the collection of status bar panels.

Declaration

delphi
property Panels: TdxStatusBarPanels read; write;

Property Value

TypeDescription
TdxStatusBarPanels

A status bar panel collection.

|

Remarks

Use the Panels property to access and manage panels displayed in the status bar control.

Available Options

Call the Panels.Add function to create new panels as demonstrated in the following code example: Create Three Status Bar Panels. The Panels.Items property provides indexed access to all panels in the status bar.

Refer to the TdxStatusBarPanels class description for detailed information on all available options.

Code Examples

Create Three Status Bar Panels

The following code example creates indicator, text label, and keyboard status panels in a TdxStatusBar control:

delphi
uses
  dxStatusBar; // Declares the TdxStatusBar control and related types
// ...

procedure TMyForm.FormCreate(Sender: TObject);
var
  ATextPanel, AIndicatorPanel, AKeyboardPanel: TdxStatusBarPanel;
  AIndicators: TdxStatusBarStateIndicators;
  AKeyboardPanelStyle: TdxStatusBarKeyboardStatePanelStyle;
begin
  dxStatusBar1.Panels.BeginUpdate; // Initiates the following batch change
  try
    // Create and configure an indicator panel
    AIndicatorPanel := dxStatusBar1.Panels.Add;
    AIndicatorPanel.PanelStyleClass := TdxStatusBarStateIndicatorPanelStyle;
    AIndicators := TdxStatusBarStateIndicatorPanelStyle(AIndicatorPanel.PanelStyle).Indicators;
    AIndicators.Add.IndicatorType := sitRed; // Creates a red indicator
    // Create and configure a text panel
    ATextPanel := dxStatusBar1.Panels.Add;
    ATextPanel.PanelStyleClass := TdxStatusBarTextPanelStyle;
    (ATextPanel.PanelStyle as TdxStatusBarTextPanelStyle).Font.Style := [fsBold];
    ATextPanel.Text := 'Disconnected'; // Defines a status message for the created text panel
    ATextPanel.Fixed := False; // Disables panel width limitations
    // Create and configure a keyboard status panel
    AKeyboardPanel := dxStatusBar1.Panels.Add;
    AKeyboardPanel.PanelStyleClass := TdxStatusBarKeyboardStatePanelStyle;
    AKeyboardPanelStyle := AKeyboardPanel.PanelStyle as TdxStatusBarKeyboardStatePanelStyle;
    // Hide the scroll lock status
    AKeyboardPanelStyle.KeyboardStates := [dxksCapsLock, dxksNumLock, dxksInsert];
  finally
    dxStatusBar1.Panels.EndUpdate; // Calls EndUpdate regardless of the batch operation's success
  end;
end;
cpp
#include "dxStatusBar.hpp" // Declares the TdxStatusBar control and related types

// Add the following linker directive to the corresponding CPP source file:
#pragma link "dxStatusBar" // Required to use dxStatusBar.hpp declarations

void __fastcall TMyForm::FormCreate(TObject *Sender)
{
  TdxStatusBarPanel *ATextPanel;
  TdxStatusBarPanel *AIndicatorPanel;
  TdxStatusBarPanel *AKeyboardPanel;
  TdxStatusBarStateIndicators *AIndicators;
  TdxStatusBarKeyboardStatePanelStyle *AKeyboardPanelStyle;

  dxStatusBar1->Panels->BeginUpdate(); // Initiates the following batch change
  try
  {
    // Create and configure an indicator panel
    AIndicatorPanel = dxStatusBar1->Panels->Add();
    AIndicatorPanel->PanelStyleClass = __classid(TdxStatusBarStateIndicatorPanelStyle);
    AIndicators =
      static_cast<TdxStatusBarStateIndicators*>(
        static_cast<TdxStatusBarStateIndicatorPanelStyle*>(AIndicatorPanel->PanelStyle)->Indicators);
    AIndicators->Add()->IndicatorType = sitRed; // Creates a red indicator

    // Create and configure a text panel
    ATextPanel = dxStatusBar1->Panels->Add();
    ATextPanel->PanelStyleClass = __classid(TdxStatusBarTextPanelStyle);
    static_cast<TdxStatusBarTextPanelStyle*>(ATextPanel->PanelStyle)->Font->Style = TFontStyles() << fsBold;
    ATextPanel->Text = "Disconnected"; // Defines a status message for the created text panel
    ATextPanel->Fixed = false; // Disables panel width limitations

    // Create and configure a keyboard status panel
    AKeyboardPanel = dxStatusBar1->Panels->Add();
    AKeyboardPanel->PanelStyleClass = __classid(TdxStatusBarKeyboardStatePanelStyle);
    AKeyboardPanelStyle =
      static_cast<TdxStatusBarKeyboardStatePanelStyle*>(AKeyboardPanel->PanelStyle);

    // Hide the scroll lock status
    AKeyboardPanelStyle->KeyboardStates =
      TdxStatusBarKeyboardStates() << dxksCapsLock << dxksNumLock << dxksInsert;
  }
  __finally
  {
    dxStatusBar1->Panels->EndUpdate(); // Calls EndUpdate regardless of the batch operation's success
  }
}

Create and Populate Indicator Panels

The following code example creates an indicator panel in an existing TdxStatusBarPanel component and populates the panel with five different indicators:

delphi
uses
  dxStatusBar; // Declares the TdxStatusBarPanel component and all related types
// ...

var
  AIndicatorPanel: TdxStatusBarPanel;
  AIndicators: TdxStatusBarStateIndicators;
begin
  AIndicatorPanel := dxStatusBar1.Panels.Add;
  AIndicatorPanel.PanelStyleClass := TdxStatusBarStateIndicatorPanelStyle;
  AIndicators := (AIndicatorPanel.PanelStyle as TdxStatusBarStateIndicatorPanelStyle).Indicators;
  AIndicators.BeginUpdate; // Initiates the following batch change
  try
    AIndicators.Add.IndicatorType := sitRed;
    AIndicators.Add.IndicatorType := sitYellow;
    AIndicators.Add.IndicatorType := sitGreen;
    AIndicators.Add.IndicatorType := sitPurple;
    AIndicators.Add.IndicatorType := sitOff;
  finally
    AIndicators.EndUpdate; // Calls EndUpdate regardless of the batch operation's success
  end;
end;
cpp
#include "dxStatusBar.hpp" // Declares the TdxStatusBarPanel component and all related types

// Add the following linker directive to the corresponding CPP source file:
#pragma link "dxStatusBar" // Required to use dxStatusBar.hpp declarations

  // ...
  TdxStatusBarPanel *AIndicatorPanel;
  TdxStatusBarStateIndicators *AIndicators;

  AIndicatorPanel = dxStatusBar1->Panels->Add();
  AIndicatorPanel->PanelStyleClass = __classid(TdxStatusBarStateIndicatorPanelStyle);
  AIndicators = dynamic_cast<TdxStatusBarStateIndicatorPanelStyle*>(AIndicatorPanel->PanelStyle)->Indicators;
  AIndicators->BeginUpdate(); // Initiates the following batch change
  try
  {
    AIndicators->Add()->IndicatorType = sitRed;
    AIndicators->Add()->IndicatorType = sitYellow;
    AIndicators->Add()->IndicatorType = sitGreen;
    AIndicators->Add()->IndicatorType = sitPurple;
    AIndicators->Add()->IndicatorType = sitOff;
  }
  __finally
  {
    AIndicators->EndUpdate(); // Calls EndUpdate regardless of the batch operation's success
  }

See Also

TdxCustomStatusBar.GetPanelAt Function

TdxCustomStatusBar Class

TdxCustomStatusBar Members

dxStatusBar Unit