Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Inside FlowLayoutPanel.Controls is a method function called SetChildIndex(Control c, int index) which allows you to set an object to a specific index.</p> <p>Since FlowLayoutPanel uses control's indices to determine which order to draw them in, you can set this to whichever control's index you are wanting to swap with, and it will bump that controls index up by one, and every one after that.</p> <p>Here is snippet from my <a href="http://gkindel.blogspot.com/2009/07/drag-and-drop-picturebox-on.html" rel="noreferrer">blog</a> of reordering PictureBoxes in a flowlayoutpanel </p> <p>// add FlowLayoutPanel on a Winform - named flowLayoutPanel1</p> <pre><code>public partial class TestForm: Form { public TestForm() { InitializeComponent(); this.flowLayoutPanel1.AllowDrop = true } private void AddImageToBlog(System.Drawing.Image image) { PictureBox pbox = new PictureBox(); pbox.SizeMode = PictureBoxSizeMode.Zoom; pbox.Height = (_picturebox_height * _ScaleFactor); pbox.Width = (_picturebox_width * _ScaleFactor); pbox.Visible = true; pbox.Image = image; pbox.MouseDown += new MouseEventHandler(pbox_MouseDown); pbox.DragOver += new DragEventHandler(pbox_DragOver); pbox.AllowDrop = true; flpNewBlog.Controls.Add(pbox); } void pbox_DragOver(object sender, DragEventArgs e) { base.OnDragOver(e); // is another dragable if (e.Data.GetData(typeof(PictureBox)) != null) { FlowLayoutPanel p = (FlowLayoutPanel)(sender as PictureBox).Parent; //Current Position int myIndex = p.Controls.GetChildIndex((sender as PictureBox)); //Dragged to control to location of next picturebox PictureBox q = (PictureBox) e.Data.GetData(typeof(PictureBox)); p.Controls.SetChildIndex(q, myIndex); } } void pbox_MouseDown(object sender, MouseEventArgs e) { base.OnMouseDown(e); DoDragDrop(sender, DragDropEffects.All); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload