Q:

Windows Forms Elements - Swap Spots

Is there any way I can take two WinForms elements of the same size/type, and just swap their positions?
I want to do this because we have a drop-down with two values, and depending on its value we want to enter data on either the left or right hand side of the form, however, it's the same data and into the same fields, but you need to see locked fields on the other side.
My idea was just to have a bunch of locked fields and the actual fields, side by side, and have the drop-down just swap them based on its value.
Is there a way to do this?
I know I could just grab the fields positions, and reset them, but I thought there might be a cleaner method to do this.

A:

If they are side-by-side as you suggest, you just need to swap their Left property:
int tmp = control1.Left;
control1.Left = control2.Left;
control2.Left = tmp;

You could also swap their top properties if they are not the same (i.e. they are not actually side-by-side).
Of course, this only works if they are in the same parent control. If they are not, you will need to remove them from their parents and add them back to the other parent.

