Let's say you have two
For the simple case, where both controls are on the same
FlowLayoutPanel, use the
SetChildIndex method on
Something like this ...
var alphaIndex = panel.Controls.IndexOf(controlAlpha); var betaIndex = panel.Controls.IndexOf(controlBeta); panel.Controls.SetChildIndex(controlAlpha, betaIndex); panel.Controls.SetChildIndex(controlBeta, alphaIndex);
Note: I haven't handled sequence here properly - you need to put the earlier control into place first, else when the second is moved ahead of it, the resulting index will be one too high. But that's an exercise for the reader.
For the more complex case, where the controls are on different
FlowLayoutPanels, the code is simpler (sequence doesn't matter so much) and more complicated (each control needs to be removed from one panel and added to the other).