RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TFlowPanel Class

TFlowPanel implements a flow panel control in which components are placed in pre-defined locations.

Pascal
TFlowPanel = class(TCustomFlowPanel);
C++
class TFlowPanel : public TCustomFlowPanel;

Use TFlowPanel to put an empty flow panel on a form. The major difference between a traditional panel and a flow panel is the way in which controls are placed. With a traditional panel, you place a control (such as a button) in a specific location. You can freely move that control to any location within the panel using the mouse. In a flow panel, each control is placed in a specific location, regardless of where you place it with the mouse. The automatic location is controlled by the FlowStyle property. For example, using the default FlowStyle property of LeftRightTopBottom, the first control you add to the flow panel snaps to the top left corner. The second control that you add snaps next to the first control, and so on.  

C++ Examples: 

 

//
//This example demonstrates the use of Flow panel to automatically
//align a set of controls and the different methods that can be used for that.
//A Stack is used to control the order of destruction of buttons.
//
void __fastcall TForm2::btAButtonClick(TObject *Sender)
{
    TButton *thisButton;
    TButton *lastButton;
    String temp;

    /* Sender is a TButton, cast it */
    thisButton = dynamic_cast<TButton*>(Sender);

    if (m_Stack->Count() > 0)
    {
        /* If there are buttons in stack, peek it */
        lastButton = dynamic_cast<TButton*>(m_Stack->Peek());

        /* Change the captions of this button and the last one */
        temp = thisButton->Caption;
        thisButton->Caption = lastButton->Caption;
        lastButton->Caption = temp;
    }
}

void __fastcall TForm2::btAddButtonClick(TObject *Sender)
{
    /* Create a new button */
    TButton *button = new TButton(m_FlowPane);

    button->Parent = m_FlowPane;
    button->Caption = IntToStr(m_Stack->Count());
    button->OnClick = btAButtonClick;

    /* Push the button to the stack */
    m_Stack->Push(button);
}

void __fastcall TForm2::btReArrangeClick(TObject *Sender)
{
    /* Change the current flow style (rotate them) */
    TFlowStyle newFlowStyle = m_FlowPane->FlowStyle;

    if (newFlowStyle == fsBottomTopRightLeft)
        newFlowStyle = fsLeftRightTopBottom;
    else
        newFlowStyle = newFlowStyle + 1;

    m_FlowPane->FlowStyle = newFlowStyle;
}

void __fastcall TForm2::btRemoveButtonClick(TObject *Sender)
{
    TButton *button;

    if (m_Stack->Count() > 0)
    {
        /* if the stack is not empty, pop the last button */
        button = dynamic_cast<TButton*>(m_Stack->Pop());
        delete button;
    }
}

void __fastcall TForm2::FormCreate(TObject *Sender)
{
    /* Create a new TFlowPanel pane and align it to client */
    m_FlowPane = new TFlowPanel(this);
    m_FlowPane->Parent = this;
    m_FlowPane->Align = alClient;

    /* Set the initial flowing style */
    m_FlowPane->FlowStyle = fsLeftRightTopBottom;

    /* Create the button stack */
    m_Stack = new TObjectStack();
}

void __fastcall TForm2::FormDestroy(TObject *Sender)
{
    /* Destroy the stack also */
    delete m_Stack;
}

 

Delphi Examples: 

{
This example demonstrates the use of Flow panel to automatically
align a set of controls and the different methods that can be used for that.
A Stack is used to control the order of destruction of buttons.
}
procedure TForm2.btAButtonClick(Sender: TObject);
var
  ThisButton : TButton;
  LastButton : TButton;
  Temp       : String;
begin
  { Sender is a TButton, cast it }
  ThisButton := Sender as TButton;

  if FStack.Count > 0 then
  begin
    { If there are buttons in stack, peek it }
    LastButton := FStack.Peek() as TButton;

    { Change the captions of this button and the last one }
    Temp := ThisButton.Caption;
    ThisButton.Caption := LastButton.Caption;
    LastButton.Caption := Temp;
  end;
end;

procedure TForm2.btAddButtonClick(Sender: TObject);
var
  Button : TButton;
begin
  { Create a new button }
  Button := TButton.Create(FFlowPane);
  Button.Parent := FFlowPane;
  Button.Caption := IntToStr(FStack.Count);
  Button.OnClick := btAButtonClick;

  { Push the button to the stack }
  FStack.Push(Button);
end;

procedure TForm2.btReArrangeClick(Sender: TObject);
var
  NewFlowStyle : TFlowStyle;
begin
  { Chnage the flow order (rotate) }
  NewFlowStyle := FFlowPane.FlowStyle;

  if NewFlowStyle = fsBottomTopRightLeft then
     NewFlowStyle := fsLeftRightTopBottom
  else
    Inc(NewFlowStyle);

  FFlowPane.FlowStyle := NewFlowStyle;
end;

procedure TForm2.btRemoveButtonClick(Sender: TObject);
var
  Button : TButton;
begin
  if FStack.Count > 0 then
  begin
    { if the stack is not empty, pop the last button }
    Button := FStack.Pop() as TButton;
    Button.Free();
  end;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  { Create a new TFlowPanel pane and align it to client }
  FFlowPane := TFlowPanel.Create(Self);
  FFlowPane.Parent := Self;
  FFlowPane.Align := alClient;

  { Set the initial flowing style }
  FFlowPane.FlowStyle := fsLeftRightTopBottom;

  { Create the button stack }
  FStack := TObjectStack.Create();
end;

procedure TForm2.FormDestroy(Sender: TObject);
begin
  { Destroy the stack also }
  FStack.Free();
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!