I have a panel with buttons. my buttons are create dynamically. I want to have 4 rows with 4 buttons each. but I only get one row.
foreach (CategoriesDataSet.CategoriesRow category in DataRepository.Categories.Categories)
{
if (!category.CategoryName.Equals("ROOT"))
{
SimpleButton button = new SimpleButton();
button.Text = category.CategoryName;
button.Tag = category.CategoryId;
button.Size = new Size(82, 70);
if (lastButton != null)
button.Left = lastButton.Right + 1;
lastButton = button;
button.Click += CategoryButtonClick;
categoriesPanel.Controls.Add(button);
}
}
Desired result :
x x x x
X x x x
x x x x
This is the answer followed by the comments of Treb’s answer.
Use for loop and use modulo operator for Left property.