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))
{

}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top