/// <summary> /// Sort all buttons from a to z or reversed. /// </summary> private void btnSort_Click(object sender, EventArgs e) { sortAlphabetic = !sortAlphabetic; Image newImage; if (sortAlphabetic == true) { CmdList = CmdList.OrderBy(a => a.Text).ToList(); newImage = Properties.Resources.sort_az; } else { CmdList = CmdList.OrderByDescending(a => a.Text).ToList(); newImage = Properties.Resources.sort_za; } flowCmdList.Controls.Clear(); // refill flowLayoutPanel foreach (CmdButton c in CmdList) { flowCmdList.Controls.Add(c); } Button b = sender as Button; b.BackgroundImage = newImage; }