我在運行時生成面板。我在窗體上有一個面板,然後我在裏面有一個滾動框alClient。在該滾動框內,我動態添加面板。它們都屬於Scrollbox,我在生成它們後將它們對齊到底部。所以他們出現在另一個之上。德爾福同步面板順序與表順序
我使用的代碼如下:
Procedure TMain.AdaugaElement(numar:integer; tip:string);
var
pan:TPanel;
semn:TShape;
pos:TPoint;
lab:TLabel;
myimg:TImage;
bmpsep, dest:TBitmap;
begin
pan:=TPanel.Create(self);
pan.Parent:=ScrollBox1;
pan.Align:=alBottom;
pan.Height:=50;
pan.Name:='Layeru'+IntToStr(numar);
pan.Caption:='Elementul '+IntToStr(numar);
pan.Font.Color:=$00004F4F;
pan.Font.Quality:=fqAntialiased;
pan.Color:=$0080FFFF;
pan.OnMouseDown:=layerRowMouseDown;
pan.ParentColor:=false;
pan.ParentBackground:=false;
pan.Color:=clWhite;
Pos:= pan.ClientOrigin;
vt.AppendRecord([vt.RecordCount+1,Pan.name,numar,numar,0 ,0, 20,20,800,600,pan.Caption,tip]);
lab:=TLabel.Create(self);
lab.Parent:=pan;
lab.Left:=54;
lab.Top:=16;
lab.Font.Size:=10;
lab.Font.Color:=clBlack;
lab.Font.Style:=[];
lab.Font.Quality:=fqAntialiased;
lab.Caption:=IntToStr(numar);
Randomize;
lab.Name:='Layernumber'+IntToStr(numar);
semn:=TShape.Create(self);
semn.Parent:=pan;
semn.Left:=3;
semn.Top:=3;
semn.Height:=44;
semn.Width:=44;
semn.Pen.Color:=$00009D9D;
semn.Brush.Color:=clWhite;
myimg:=TImage.Create(self);
myimg.Width:=42;
myimg.Height:=42;
myimg.Left:=4;
myimg.Top:=4;
myImg.Visible:=true;
myimg.Proportional:=true;
myimg.Stretch:=true;
myImg.Parent:=pan;
SelectLayerPan(numar);
end;
SelectLayerPan
過程模擬所選擇的行中的表,所以當我添加一個新的面板,它顯示爲「選擇」(這是取消選擇'的所有板然後它選擇「新的面板)vt
是VirtualTable
其中我關於所生成的面板輸入信息
所以我添加面板是這樣的:
AdaugaElement(1,'type1');
AdaugaElement(2,'type1');
AdaugaElement(3,'type1');
AdaugaElement(4,'type1');
接下來,我想用鼠標來移動它們之間的面板。所以一開始我還補充說:
- panel5
- panel4
- panel3
- panel2
- panel1
(按照這個順序)
然後使用鼠標,我拖累PANEL1和panel4和panel5之間拖放。因此,他們將顯示爲:
- panel5
- **panel1**
- panel4
- panel3
- panel2
(按照這個順序)
此拖放在layerRowMouseDown完成。
但是,因爲在virtualTable我對面板的信息(在原來的順序),所以
record1: panel1 pos:1
record2: panel2 pos:2
record3: panel3 pos:3
record4: panel4 pos:4
record5: panel5 pos:5
我必須確定移動板記錄和更新它,所以它會反映其新的位置,所以VirtualTable必須如下所示:
record1: panel1 pos:4
record2: panel2 pos:1
record3: panel3 pos:2
record4: panel4 pos:3
record5: panel5 pos:5
我該怎麼做?
我的意思是,當我放下它時,如何檢測面板結束的位置?或者,也許我該如何獲得他們的容器(ScrollBox1)面板的順序?
到目前爲止,我嘗試使用FindVCLWindow(pos)
來確定面板(以及它們在scrollBox中的順序),使用面板的起始位置和倍數,但是當面板更多時,它們不再直接可見(沒有滾動),它顯然停止正常工作。
所以這不是一個解決方案
我沒有使用完全相同你的想法,但你的回答讓我感動,我發現我的解決方案。它不使用面板標籤,我使用包含在動態面板中的標籤,以及幫助使用vt(表格)的主要內容。我用過的火花想法是面板的Top屬性排序。萬分感謝 – user1137313 2015-02-13 22:34:16