Button location

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shalifar
    New Member
    • Jun 2012
    • 2

    Button location

    Hello,

    Code:
      Button[] btn = new Button[100];
            Random rnd = new Random();
            Point pt = new Point();
            public Form1()
            {
                InitializeComponent();            
                for (int i = 0; i < 100; i++)
                {
                    [B]btn[i].Location = new Point(100+25*i, 100);[/B]
                    btn[i].Height = 25;
                    btn[i].Width = 25;
                    
                }
                this.Controls.AddRange(btn);
    
            }
    I need a field of buttons. Actually, i tried a variety of things including array of points, changing 1 point's coordinates, but he still doesn't want to eat line 9. I need that line to work. Or, maybe, there is some other way?

    Thanks in advance.
    Last edited by shalifar; Jun 7 '12, 11:14 AM. Reason: new info
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    I would put this inside your for loop to start with

    Code:
    this.Controls.AddRange(btn);
    Then change it to
    Code:
    this.Controls.Add(btn[i]);

    Comment

    • shalifar
      New Member
      • Jun 2012
      • 2

      #3
      Tried it before. Nothing changed.

      Comment

      Working...