Testing for Control Type

  • Thread starter Thread starter MFRASER
  • Start date Start date
M

MFRASER

How do I loop through a collection of controls testing to see if a certain
control type already exists in the collection.

//this doesn't work
foreach(System.Windows.Forms.Control aControl in
StudyViewer_Fill_Panel.Controls)

{

if (typeof(aControl) == typeof(TestControl))

{

tmpControl = TestControl;

aControl.Show();

}

else

{

aControl.Hide();

}

}
 
How do I loop through a collection of controls testing to see if a certain
control type already exists in the collection.

//this doesn't work
foreach(System.Windows.Forms.Control aControl in
StudyViewer_Fill_Panel.Controls)

{

if (typeof(aControl) == typeof(TestControl))

{

tmpControl = TestControl;

aControl.Show();

}

else

{

aControl.Hide();

}

}

Try

foreach (System.Windows.Forms.Control ctrl in this.Controls)
{
if (ctrl.GetType() == typeof(Button))
{

}
}
 
Back
Top