I have a panel with controls in them. Controls are buttons and progressbars. I would like to add only the buttons to a list, how can I do it?
foreach (Control item in panel1.Controls)
{
//if (item.GetType() == typeof(ButtonControl)) //i tried this too...
if ((item is ButtonControl) && (item.Tag.ToString() == "It's not important"))
{
panel1.BtnList.Add(item);
}
}
Here ButtonControl is my own Control, which is inherited from Button class.
Using LINQ you can do for
System.Windows.Forms.ButtonIf you want to check the Tag value as well then you can do
EDIT:
If
ButtonControlis your own class then you can do: