For a winForm I'm building, I'm working with a TableLayoutPanel which has an arbitrary number of Textboxes and two buttons to add or remove boxes, + and -. The + and - buttons appear directly below the Textbox to which the user has given focus like so:
If the user clicks another box, the + and - buttons should move appropriately at runtime. I've been trying for a while to move the textboxes around with the .GetControlFromPosition
and .GetPositionFromControl
commands, but this doesn't seem to work as the boxes either don't move or move to different locations than intended. Whats the best way to go about and solve this issue?
You have to change the position of the two buttons and every text box between their new and old positions. If two or more controls are assigned to the same cell, all but one will be moved along to the next empty cell.
Just a suggestion which may look better and make coding easier, how about having the buttons in two narrow columns to the right of the text boxes. The ( )
below represent empty cells.
( text box ) ( ) ( )
(focused text box) (+) (-)
( text box ) ( ) ( )
( text box ) ( ) ( )
( text box ) ( ) ( )