By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,459 Members | 1,472 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,459 IT Pros & Developers. It's quick & easy.

Testing for Control Type

P: n/a
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();

}

}
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
L#
On Wed, 4 Feb 2004 11:44:05 -0800, "MFRASER"
<mf*****@henwoodenergy.com> wrote:
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))
{

}
}
--
Ludwig
mailto:ludwig_(nospamplease)stuyck@pandora(nospamp lease).be
Nov 15 '05 #2

P: n/a
if (typeof(aControl) == typeof(TestControl))


if ( aControl is TestControl )

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.