1
나는 컨트롤이있는 panel
입니다. 컨트롤은 buttons
및 progressbars
입니다. list
에만 버튼을 추가하고 싶습니다. 어떻게 할 수 있습니까?목록의 다른 컨트롤
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);
}
}
ButtonControl
는 Button
클래스에서 상속되는 내 자신의 컨트롤입니다. 당신은뿐만 아니라 태그 값을 확인하려면 System.Windows.Forms.Button
List<Button> buttonList = panel1.Controls.OfType<Button>().ToList();
은 당신이 할 수있는 당신이 할 수있는 LINQ를 사용하여
예, '훌륭합니다. 감사합니다. 하지만 이전에 Button Type에 대한 목록을 지정하고 싶습니다. (Buttoncontrol은 Buttons 클래스에서 상속받은 내 자신의 컨트롤입니다.) – bandeee
@ user1807523이 경우에는 OfType을 사용할 수 있습니다 –
Habib
@ user1807523, 패널에서 'ButtonControl'을 가져 와서'Button '목록에 추가 하시겠습니까? – Habib