Solved

Moving panels..

Posted on 2004-08-16
9
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 34

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month6 days, 1 hour left to enroll

626 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