How to move with components that i create.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Martin Prazak
    New Member
    • Apr 2011
    • 5

    How to move with components that i create.

    I have this code:
    Code:
    public partial class Form1 : Form
        {
            private Button cudlik;
            int i;
    public Form1()
      {
        InitializeComponent();
      }
    
    public void button1_Click(object sender, EventArgs e)
    {
      i++;
      cudlik = new Button();
      cudlik.Location = new System.Drawing.Point(150, 150 + 20 * i);
      cudlik.Size = new System.Drawing.Size(120, 20);
      cudlik.Name += "cudlik" + i;
      cudlik.Text += i;
      this.Controls.Add(cudlik);
      timer1.Enabled = true;
            }
    
    private void timer1_Tick(object sender, EventArgs e)
     {
       cudlik.Left += 1;
     }
    If I create the button in this way, it's moving just the last one that I create.

    I want to move with every created buttons, but I don't know how to do it.
  • hype261
    New Member
    • Apr 2010
    • 207

    #2
    What you want to do is create a container of Controls. When you create a new control you need to add it to the Forms controls, but you also need to add it to the container. In your tick event you just cycle through all the controls in the container and individually move them left.

    Comment

    • Martin Prazak
      New Member
      • Apr 2011
      • 5

      #3
      Could you please show me part of code with what you mean?
      ---------------------------------------------------------

      I figured it out! Thanks.

      Comment

      Working...