2012-01-27 49 views
1

所以我有一個流程面板和一個按鈕,它在運行時爲它添加了一覽表。我設置了雙擊事件 - 是否可以設置某種點擊(或單擊並拖動)事件來重新排列流程面板中的控件?是否可以在運行時重新排列流控面板中的控件?

我知道我們可以改變排序策略(自上而下,左右)幷包裝,但我希望組織用戶可以簡單地從一個地方拖動控件並將其重新定位到其他地方。

private void addNewWOButton_Click(object sender, EventArgs e) 
     { 
      ListView newListView = new ListView(); 
      newListView.AllowDrop = true; 
      newListView.DragDrop += listView_DragDrop; 
      newListView.DragEnter += listView_DragEnter; 
      newListView.DoubleClick += listView_DoubleClick; 

      flowPanel.Controls.Add(newListView); 
} 
+1

你在調用一個「flowpanel」實際上是一個FlowLayoutPanel控件嗎? – 2012-01-27 02:53:53

+1

[流佈局面板中的控件重新排序]的可能重複(http://stackoverflow.com/questions/425867/reordering-of-controls-within-a-flow-layout-panel)?另見:http://www.codeproject.com/Articles/48411/Using-the-FlowLayoutPanel-and-Reordering-with-Drag – 2012-01-27 02:55:48

回答

2

這會將一個控件移動到面板的頂部並向下移動其餘的控件。

  FlowLayoutPanel1.Controls.SetChildIndex(myControl, 0); 

對於拖放重新排序,您必須勾選每個控件的拖放事件。在拖放事件中獲取正在拖動的控件以及目標控件的索引位置。然後使用SetChildIndex更改索引。如果你仍然在處理這個問題,我可以挖掘一些代碼給你看。

相關問題