Solved

Moving panels..

Posted on 2004-08-16
9
253 Views
Last Modified: 2010-04-05
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
Comment
Question by:hakanfa
9 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 11811798
Why you don't use ToolBars with CoolBar?
0
 

Author Comment

by:hakanfa
ID: 11812542
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
 
LVL 33

Expert Comment

by:Slick812
ID: 11817252
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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:hakanfa
ID: 11817442
?? 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
 
LVL 3

Expert Comment

by:Tyrsis
ID: 11817684
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
 
LVL 12

Expert Comment

by:esoftbg
ID: 11826555
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
 
LVL 12

Accepted Solution

by:
esoftbg earned 250 total points
ID: 11826625
download a working example from :
page:        http://www.geocities.com/esoftbg/
  link:        Q_21095252.zip
0
 

Author Comment

by:hakanfa
ID: 12041593
Works like a charm ;) Sorry for the delay of accepting the answer.

Hokki
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12041636
Hi Hokki,
I am glad that the solution > Works like a charm
Best Regards,
Emil
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question