I am trying to create a system that has X amount of buttons, like a POS system. Number of buttons will be different based on the number of items user input. My question is if I should create it dynamically like the following:
private void createButton(int numOfBtn)
{
for (int i = 0; i < numOfBtn; i++)
{
Button btn = new Button();
btn.Name = "button";
btn.Text = "button";
btn.ForeColor = Color.White;
btn.BackColor = Color.Green;
btn.Font = new Font("Serif", 24, FontStyle.Bold);
btn.Width = 170;
btn.Height = 80;
btn.TextAlign = ContentAlignment.MiddleCenter;
btn.Margin = new Padding(5);
}
}
Should create buttons one by one on the designer, dynamically like the above code or if there is a better way of doing so?
Also, currently I am having the windows set to Maximum size when it launches, so when I am creating the buttons, how can I tell if the number of button has max out the space(flowlayout).
Edit: Is it better to create all the buttons from the designer first and assign value of it after? but this way there will always have a maximum amount of buttons, let says if I create 20 buttons from the designer, at max I can only assign twenty items.. what would the better way of doing such task?