• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

Moving panels..

Hello!

Can anyone help me with a problem regarding moving panels inside another panel..?
Detailed description:

On a Form I have a "MainPanel" aligned alTop. Inside this Panel I have 3 panels aligned alTop also.
Now I want to be able to move (change position) of these panels (when dragging a small image in the
upper left corner)  so that Panel1 will be placed as second  panel and Panel 3 placed as the first panel
and so on...

Any suggestions?


 
0
hakanfa
Asked:
hakanfa
1 Solution
 
Mohammed NasmanSoftware DeveloperCommented:
Why you don't use ToolBars with CoolBar?
0
 
hakanfaAuthor Commented:
Well I dont think that it will do it. You see I have an application (MDI) showing data from a database. I have divided the MDChild into sections using panels. Now I want to give the user the possibility to change the layout of the MDIChild, by changing the order of the panels.

Hokki
0
 
Slick812Commented:
hello hakanfa ,
????
I would NOT use the 3 panels aligned to alTop, I would not have them aligned to anywhere, with alNone

and then I would just set all their positions with code

panel2.Top := 0;
panel1.Top := Panel2.Height;
panel3.Top := panel2.Height + panel1.Height;


or

panel3.Top := 0;
panel2.Top := Panel2.Height;
panel1.Top := panel2.Height + panel1.Height;
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
hakanfaAuthor Commented:
?? Now I don't understand..How do I handle the the movement of the panels? I mean, when the user want to shift the first panel to be the second one? The idea is that i have a small bitmap in every panels upper right corner, when thr user "grabbs" the bitmap (keeps the mousebutton pressed) he will be able to shift the position of these panels..
0
 
TyrsisCommented:
I'm not entirely certain how much control you need.  In this example I don't use any alignment.  If you want the panels to shrink down to 1 pixel high, then you will have to modify it a bit.  But you will be able to drag the panels over one another.  In this example I used 3 Panels of the same height one on top of another and set their OnMouseDown, OnDragOver and OnDragDrop to the same events.  Hope this is what you require.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    MainPanel: TPanel;
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    procedure PanelMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure PanelDragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure PanelDragDrop(Sender, Source: TObject; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.PanelMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
    Panel : TPanel;
begin
    if(Sender is TPanel) then
    begin
        Panel := Sender as TPanel;
        Panel.BeginDrag(false);
    end;
end;

procedure TForm1.PanelDragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
    if(Source is TPanel) then
    begin
        Accept := true;
    end;
end;

procedure TForm1.PanelDragDrop(Sender, Source: TObject; X, Y: Integer);
var
    SourcePanel, DestPanel : TPanel;
    srcRect, dstRect : TRect;
    iTop : Integer;
begin
    if(Source = Sender) then
        exit;

    if(Source is TPanel) and (Sender is TPanel) then
    begin
        SourcePanel := Source as TPanel;
        DestPanel := Sender as TPanel;

        iTop := SourcePanel.Top;

        SourcePanel.Top := DestPanel.Top;
        DestPanel.Top := iTop;
    end;
end;

end.

Here is the form as Text:

object Form1: TForm1
  Left = 817
  Top = 244
  Width = 505
  Height = 430
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object MainPanel: TPanel
    Left = 0
    Top = 0
    Width = 497
    Height = 137
    Align = alTop
    TabOrder = 0
    object Panel3: TPanel
      Left = 0
      Top = 80
      Width = 497
      Height = 41
      Caption = 'Panel3'
      TabOrder = 2
      OnDragDrop = PanelDragDrop
      OnDragOver = PanelDragOver
      OnMouseDown = PanelMouseDown
    end
    object Panel2: TPanel
      Left = 1
      Top = 41
      Width = 495
      Height = 41
      Caption = 'Panel2'
      TabOrder = 0
      OnDragDrop = PanelDragDrop
      OnDragOver = PanelDragOver
      OnMouseDown = PanelMouseDown
    end
    object Panel1: TPanel
      Left = 2
      Top = 1
      Width = 495
      Height = 41
      Caption = 'Panel1'
      TabOrder = 1
      OnDragDrop = PanelDragDrop
      OnDragOver = PanelDragOver
      OnMouseDown = PanelMouseDown
    end
  end
end
0
 
esoftbgCommented:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
  Forms,   Dialogs, ComCtrls, ExtCtrls, Spin;

type
  TMoveDirection = (mdUp, mdDn);
  TPanelArr = array of TPanel;
  TForm1 = class(TForm)
    PanelMain: TPanel;
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    SpinButton1: TSpinButton;
    SpinButton2: TSpinButton;
    SpinButton3: TSpinButton;
    procedure FormCreate(Sender: TObject);
    procedure SpinButton1UpClick(Sender: TObject);
    procedure SpinButton1DownClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private   { Private declarations }
  public    { Public declarations }
    PanelArr: TPanelArr;
    procedure Move_Panels(Button: TMoveDirection);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  I:      Integer;
  L:      Integer;
begin
  for I := 0 to ComponentCount-1 do
  if ((Components[I] as TControl).Parent=PanelMain) then
  if ((Components[I] as TControl).ClassType=TPanel) then
  begin
    L := Length(PanelArr) + 1;
    SetLength(PanelArr, L);
    PanelArr[L-1] := (Components[I] as TPanel);
    PanelArr[L-1].Align := alNone;
  end;
end;

procedure TForm1.Move_Panels(Button: TMoveDirection);
var
  B:      Integer;
  C:      Integer;
  I:      Integer;
  J:      Integer;
  N:      Integer;
  F:      Boolean;
  PT:     TPanel;
begin
  N := Length(PanelArr);
  for B := 0 to N-2 do
  begin
    F := False;
    for C := 0 to N-B-2 do
    begin
      if (PanelArr[C+1].Top<PanelArr[C].Top) then
      begin
        PT := PanelArr[C];
        PanelArr[C] := PanelArr[C+1];
        PanelArr[C+1] := PT;
        F := True;
      end;
    end;
    if not F then
      Break; // B
  end;
  case Button of
    mdUp:
    begin
      J := PanelArr[N-1].Top;
      for I := N-1 downto 1 do
      begin
        PanelArr[I].Top := PanelArr[I-1].Top;
      end;
      PanelArr[0].Top := J;
    end;
    mdDn:
    begin
      for I := 0 to N-2 do
        PanelArr[I].Top := PanelArr[I+1].Top;
      PanelArr[N-1].Top := 0;
    end;
  end;
end;

procedure TForm1.SpinButton1UpClick(Sender: TObject);
begin
  Move_Panels(mdUp);
end;

procedure TForm1.SpinButton1DownClick(Sender: TObject);
begin
  Move_Panels(mdDn);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  SetLength(PanelArr, 0);
end;

end.
0
 
esoftbgCommented:
download a working example from :
page:        http://www.geocities.com/esoftbg/
  link:        Q_21095252.zip
0
 
hakanfaAuthor Commented:
Works like a charm ;) Sorry for the delay of accepting the answer.

Hokki
0
 
esoftbgCommented:
Hi Hokki,
I am glad that the solution > Works like a charm
Best Regards,
Emil
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now