Back to Devexpress

TdxLayoutSplitterItem Class

vcl-dxlayoutcontainer-1773232a.md

latest10.1 KB
Original Source

TdxLayoutSplitterItem Class

A splitter that delimits two adjacent layout items.

Declaration

delphi
TdxLayoutSplitterItem = class(
    TdxLayoutDirectionalItem
)

Remarks

A splitter is an auxiliary layout item that allows you to delimit two layout items and resize them without the Customization Form.

Near, Far, and Target Layout Items

Near and far item positions depend on the parent layout group‘s LayoutDirection property value:

ldVertical Default. The group arranges items from top to bottom. The near item is above the splitter, and the far item is below it.ldHorizontalThe group arranges items from left to right. Near and far items are to the left and right of a splitter, respectively.

The target item is the near or far layout item associated with the splitter, depending on AlignVert and AlignHorz property values as well as the parent group direction.

For example, the near item is the splitter target if the parent group is horizontally arranged, and the AlignHorz property is set to ahLeft:

Main API Members

The list below outlines key members of the TdxLayoutSplitterItem class. These members allow you to configure the layout splitter and manage its states.

User Interaction Options

AllowCloseOnClickSpecifies if a click on the splitter expands or collapses the target layout item.OnCanResizeAllows you to prevent users from resizing layout items delimited by the splitter.

Splitter State Management

Close | IsClosed | OpenCollapse and expand the splitter’s target layout item.OnClosed | OnMoved | OnOpenedAllow you to respond to splitter collapse, expand, and move operations.

General-Purpose API Members

AlignHorz | AlignVertSpecify the target layout item in horizontally and vertically arranged parent groups.GetFarItem | GetNearItemProvide access to layout items delimited by the splitter.VisibleSpecifies if the layout splitter is visible.

Code Examples

Track Splitter Movement

The following code example demonstrates an OnMoved event handler that displays names and sizes of layout items delimited by the currently dragged splitter in a horizontally arranged layout group:

delphi
procedure TMyForm.dxLayoutSplitterItem1Moved(
  Sender: TdxLayoutSplitterItem; AArgs: TdxLayoutSplitterItemMovedEventArgs);
begin
  Caption := AArgs.NearItem.Name + ' Item Width: ' + IntToStr(AArgs.NewNearItemBounds.Width) + ' ' +
    AArgs.FarItem.Name + ' Item Width: ' + IntToStr(AArgs.NewFarItemBounds.Width);
end;
cpp
void __fastcall TMyForm::dxLayoutSplitterItem1Moved(
  TdxLayoutSplitterItem *Sender, TdxLayoutSplitterItemMovedEventArgs *AArgs)
{
  Caption = AArgs->NearItem->Name + " Item Width: " + IntToStr(AArgs->NewNearItemBounds->Width) + " " +
    AArgs->FarItem->Name + " Item Width: " + IntToStr(AArgs->NewFarItemBounds->Width);
}

Keep Only One Grouped Layout Item Expanded at a Time

The code example in this section demonstrates OnClosed and OnOpened event handlers that allow you to keep only one layout item expanded within a layout group that contains items delimited by splitters. The form’s OnCreate event handler assigns the same event handlers to all splitters within the target group.

delphi
procedure TMyForm.SplitterItemClosed(Sender: TdxLayoutSplitterItem;
  AArgs: TdxLayoutSplitterItemMovedEventArgs);
var
  I: Integer;
begin
  for I := 0 to dxLayoutGroup1.Count - 1 do
    if((dxLayoutGroup1.Items[I].ClassType = TdxLayoutSplitterItem) and
      (dxLayoutGroup1.Items[I] <> Sender)) then
      if (dxLayoutGroup1.Items[I] as TdxLayoutSplitterItem).IsClosed then
        (dxLayoutGroup1.Items[I] as TdxLayoutSplitterItem).Open;
end;

procedure TMyForm.SplitterItemOpened(Sender: TdxLayoutSplitterItem;
  AArgs: TdxLayoutSplitterItemMovedEventArgs);
var
  I: Integer;
begin
  for I := 0 to dxLayoutGroup1.Count - 1 do
    if ((dxLayoutGroup1.Items[I].ClassType = TdxLayoutSplitterItem) and
       (dxLayoutGroup1.Items[I] <> Sender)) then
       if not (dxLayoutGroup1.Items[I] as TdxLayoutSplitterItem).IsClosed then
         (dxLayoutGroup1.Items[I] as TdxLayoutSplitterItem).Close;
end;

procedure TMyForm.FormCreate(Sender: TObject);
var
  I: Integer;
begin
  for I := 0 to dxLayoutGroup1.Count - 1 do
    if(dxLayoutGroup1.Items[I].ClassType = TdxLayoutSplitterItem) then
    begin
      (dxLayoutGroup1.Items[I] as TdxLayoutSplitterItem).AllowCloseOnClick := True;
      (dxLayoutGroup1.Items[I] as TdxLayoutSplitterItem).OnOpened := SplitterItemOpened;
      (dxLayoutGroup1.Items[I] as TdxLayoutSplitterItem).OnClosed := SplitterItemClosed;
    end;
end;
cpp
void __fastcall TMyForm::SplitterItemClosed(TdxLayoutSplitterItem *Sender,
  TdxLayoutSplitterItemMovedEventArgs *AArgs)
{
  for(int i = 0; i < dxLayoutGroup1->Count; i++)
  {
    if((dxLayoutGroup1->Items[i]->ClassType() == __classid(TdxLayoutSplitterItem)) &&
      (dxLayoutGroup1->Items[i] != Sender))
      {
        if(dynamic_cast<TdxLayoutSplitterItem*>(dxLayoutGroup1->Items[i]->IsClosed))
          dynamic_cast<TdxLayoutSplitterItem*>(dxLayoutGroup1->Items[i])->Open();
      }
  }
}

void __fastcall TMyForm::SplitterItemOpened(TdxLayoutSplitterItem *Sender,
  TdxLayoutSplitterItemMovedEventArgs *AArgs)
{
  for(int i = 0; i < dxLayoutGroup1->Count; i++)
  {
    if((dxLayoutGroup1->Items[i]->ClassType() == __classid(TdxLayoutSplitterItem)) &&
      (dxLayoutGroup1->Items[i] != Sender))
      {
        if(!dynamic_cast<TdxLayoutSplitterItem*>(dxLayoutGroup1->Items[i]->IsClosed))
          dynamic_cast<TdxLayoutSplitterItem*>(dxLayoutGroup1->Items[i])->Close();
      }
  }
}

void __fastcall TMyForm::FormCreate(TObject *Sender)
{
  for(int i = 0; i < dxLayoutGroup1->Count; i++)
  {
    if(dxLayoutGroup1->Items[i]->ClassType == __classid(TdxLayoutSplitterItem))
    {
      dynamic_cast<TdxLayoutSplitterItem*>(dxLayoutGroup1->Items[i])->AllowCloseOnClick = true;
      dynamic_cast<TdxLayoutSplitterItem*>(dxLayoutGroup1->Items[i])->OnOpened = SplitterItemOpened;
      dynamic_cast<TdxLayoutSplitterItem*>(dxLayoutGroup1->Items[i])->OnClosed = SplitterItemClosed;
    }
  }
}

Other Auxiliary Layout Items

TdxLayoutEmptySpaceItemAn auxiliary layout item used to provide an empty region within a layout control.TdxLayoutImageItemAn auxiliary layout item used as an image container.TdxLayoutSeparatorItemA separator used to visually separate layout elements into small, logical groups within a layout group.TdxLayoutLabeledItemA standalone label that can be associated with any layout element.

Inheritance

TObject TPersistent TComponent TcxCustomComponent TdxCustomLayoutItem TdxLayoutBasicItem TdxLayoutNonLabeledItem TdxLayoutDirectionalItem TdxLayoutSplitterItem

See Also

TdxLayoutItem Class

TdxLayoutSplitterItem Members

dxLayoutContainer Unit