Back to Devexpress

TdxLayoutSplitterItemMovedEvent Type

vcl-dxlayoutcontainer-c3c51968.md

latest9.3 KB
Original Source

TdxLayoutSplitterItemMovedEvent Type

The procedural type for layout splitter movement events.

Declaration

delphi
TdxLayoutSplitterItemMovedEvent = procedure(Sender: TdxLayoutSplitterItem; AArgs: TdxLayoutSplitterItemMovedEventArgs) of object;

Parameters

NameTypeDescription
SenderTdxLayoutSplitterItem

Provides access to the layout splitter that raised the movement event.

| | AArgs | TdxLayoutSplitterItemMovedEventArgs |

Provides access to information on the occurred layout splitter movement operation.

You can use Args.NewFarItemBounds and Args.NewNearItemBounds properties to identify new dimensions and positions of two delimited layout items after the splitter movement operation has occurred.

|

Remarks

Splitter movement events allow you to track state and position changes of layout items delimited by a splitter in a group.

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:

Accessible Event Parameters

SenderAllows you to identify and access the layout splitter that raised the event.Args

Allows you to access layout items delimited by the Sender splitter and identify their boundaries before and after the splitter movement operation:

Args.NearItem | Args.FarItemProvide access to two layout items delimited by the splitter.Args.NewNearItemBounds | Args.NewFarItemBoundsReturn new boundaries of the delimited layout items.Args.OldNearItemBounds | Args.OldFarItemBoundsReturns boundaries of the delimited layout items before the splitter movement operation.

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;
    }
  }
}

Direct TdxLayoutSplitterItemMovedEvent Type References

The following events reference the TdxLayoutSplitterItemMovedEvent procedural type:

TdxLayoutSplitterItem.OnClosedAllows you to respond to a splitter collapse operation.TdxLayoutSplitterItem.OnMovedAllows you to track splitter movements.TdxLayoutSplitterItem.OnOpenedAllows you to respond to a layout splitter expand operation. See Also

TdxLayoutItemCanResizeEvent Procedural Type

dxLayoutContainer Unit