0

How would I make it so when a person clicks on a button, all of the objects on the user control shift location 25 to the right?

Rohan Pas
  • 177
  • 1
  • 14
  • 2
    What have you tried so far? are all objects `Control`s? – vipersassassin Mar 26 '17 at 03:00
  • For a start, I would advise you to put all of these controls in a `Panel`. Then you will only have to move one control (namely, that panel). Grouping them like this seems appropriate, since, if they have to move together, they probably belong together in some way, after all. – stakx - no longer contributing Mar 26 '17 at 11:11

2 Answers2

1

You can use the VisualTreeHelper.GetChild and create a recursive method to return all children in the tree for that UserControl. https://msdn.microsoft.com/en-us/library/system.windows.media.visualtreehelper.getchild(v=vs.110).aspx

Then you can use a translate transformation and apply it to the control. Using code similar to the answer here WPF. Easiest way to move Image to (X,Y) programmatically?

Community
  • 1
  • 1
David Kucsai
  • 81
  • 1
  • 4
1

Are you trying to move all controls of the form? Then write something like this:

        private void button1_click(object sender, EventArgs e)
    {
        foreach(Control ctrl in this.Controls)
        {
            ctrl.Left += 25;
        }
    }
SOCIOPATH
  • 72
  • 7