I have some buttons on a Winform app, and using the following code have changed their back colour and text.
List<Button> buttons = new List<Button>();
foreach (Button bt in panel1.Controls)
{
if (bt is Button)
{
buttons.Add(bt);
}
}
int btext = 1;
foreach (var button in buttons)
{
button.Text = btext.ToString();
button.BackColor = Color.White;
btext++;
}
But on viewing the form when its run the button at the bottom right of the grid of buttons has the text “1” and the button at the top left of the grid has the text “36” displayed on it. I was hoping, and thought, that it should be the other way round. Why is it as it is and how do I change it please? Many thanks.
I think that the order in which controls are added to the
panel1.Controlscollection is relevant here. You can try to set the tab order for the buttons and then sort them byTabIndexproperty.