Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to drag and drop TPanels within a scrollbox to rearrange the order Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
26-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
132
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

All I want to do is to allow the user to drag/ drop panels within a scrollbox to 
rearrange the order. They are initially created in alpha order by caption anf 
pointers stored in a stringlist. When the user moves one it is moved in the 
stringlist, the scrollbox is cleared (note: the panels cannot be freed because they 
contain info) and re-parented in stringlist sequence. If you do more than one move, 
the resulting sequence of the panels in the scrollbox seems completely random, and 
certainly bears no resemblance to the sequence in the stringlist! I have tried 
doing this by index up from and downto zero; neither works.

Answer:

All your trouble comes from using the alTop style for the panels. Simply set it to 
alNone and size and position the panels in code, using their SetBounds method.

1   procedure TForm1.FormCreate(Sender: TObject);
2   var
3     iCount: integer;
4     APanel: TPanel;
5     y: Integer;
6   begin
7     AStrList := TStringList.Create;
8     y := 0;
9     for iCount := 0 to 4 do
10    begin
11      APanel := TPanel.Create(Self);
12      with APanel do
13      begin
14        Name := 'P' + IntToStr(iCount);
15        Align := alNone;
16        OnMouseDown := PanelMouseDown;
17        OnDragOver := PanelDragOver;
18        OnDragDrop := PanelDragDrop;
19        SetBounds(0, y, scrollbox1.clientwidth, height);
20        Inc(y, height);
21      end;
22      AStrList.AddObject(APanel.Caption, APanel);
23    end;
24    for iCount := 0 to (AStrList.Count - 1) do
25      TPanel(AStrList.Objects[iCount]).Parent := ScrollBox1;
26  end;
27  
28  procedure TForm1.PanelDragDrop(Sender, Source: TObject; X, Y: Integer);
29  var
30    iFrom, iTo, iCount: integer;
31  begin
32    iFrom := AStrList.IndexOfObject(TPanel(Sender));
33    iTo := AStrList.IndexOfObject(TPanel(Source));
34    AStrList.Move(iFrom, iTo);
35    y := 0;
36    for iCount := 0 to (AStrList.Count - 1) do
37      with TPanel(AStrList.Objects[iCount]) do
38      begin
39        Top := y;
40        Inc(y, Height);
41      end;
42  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC