Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Auto Arrange Dynamic Buttons

$
0
0

As you can see from my previous posts I have been getting some help on the forums in reference to creating dynamic buttons and everything works great so far. I have one problem though.  I have been trying to get the buttons to auto go to next line right below the button. With the code below I added a variable countWords and when it reaches a certain number or works will change the x coord and place a new line.  The problem with it is that I used multiplication so when it hits the third line it goes too far in the groupbox.  Is there an easier away to arrange these buttons on the groupbox?

private void createButtons(int length)
        {
            Button[] buttons = new Button[length];
            for (int i = 0; i < buttons.Length; i++)
            {
                buttons[i] = new Button();
                Point p = new Point(10, (i + 1) * 30);
                buttons[i].Location = p;
                buttons[i].Text = "Button" + i.ToString();
                buttons[i].Name = "Button" + i.ToString();
                this.Controls.Add(buttons[i]);
            }
        }


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>