397,629 Members | 1,856 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 397,629 IT Pros & Developers. It's quick & easy.

How to determine the control has the specific properties or events or not?

ABC
P: n/a
ABC
I want to check the form's controls have or not the specific properties or
events. How to determine or gather the properties list under the run-time
environment?
Jan 3 '06 #1
Share this Question
Share on Google+
4 Replies


Nicholas Paldino [.NET/C# MVP]
P: n/a
ABC,

You want to use Reflection for this. First, get the type of the object
through a call to GetType. Once you do this, you will want to call
GetProperties or GetEvents to get the properties or events.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

"ABC" <abc@abc.com> wrote in message
news:%23J5uNrAEGHA.984@tk2msftngp13.phx.gbl...
I want to check the form's controls have or not the specific properties or
events. How to determine or gather the properties list under the run-time
environment?

Jan 3 '06 #2

ABC
P: n/a
ABC
I am a newie about Reflection. I have not any ideas about Reflection
concept. May I have some tutorials or artists from internet? Any
recommandation?
"Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote in
message news:eSaA10AEGHA.2872@TK2MSFTNGP14.phx.gbl...
ABC,

You want to use Reflection for this. First, get the type of the object
through a call to GetType. Once you do this, you will want to call
GetProperties or GetEvents to get the properties or events.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

"ABC" <abc@abc.com> wrote in message
news:%23J5uNrAEGHA.984@tk2msftngp13.phx.gbl...
I want to check the form's controls have or not the specific properties or
events. How to determine or gather the properties list under the run-time
environment?


Jan 3 '06 #3

Peter Rilling
P: n/a
What exactly are you trying to do? Simply knowing if something has a
particular property does not help if you do not know the behavior, and
reflection will not identify the behavior. If you provide more information,
than a simpler solution might work.

"ABC" <abc@abc.com> wrote in message
news:%23L1s4XBEGHA.1288@TK2MSFTNGP09.phx.gbl...
I am a newie about Reflection. I have not any ideas about Reflection
concept. May I have some tutorials or artists from internet? Any
recommandation?
"Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote
in message news:eSaA10AEGHA.2872@TK2MSFTNGP14.phx.gbl...
ABC,

You want to use Reflection for this. First, get the type of the
object through a call to GetType. Once you do this, you will want to
call GetProperties or GetEvents to get the properties or events.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

"ABC" <abc@abc.com> wrote in message
news:%23J5uNrAEGHA.984@tk2msftngp13.phx.gbl...
I want to check the form's controls have or not the specific properties
or events. How to determine or gather the properties list under the
run-time environment?



Jan 3 '06 #4

Brant Estes
P: n/a
ABC -

Reflection allows you to programatically examine and work with objects
at runtime. This is a very powerful feature of .NET which allows you
to interact with objects which you may not know how to work with at
design time. With reflection, you can obtain information about
methods, constructors, fields, events, anything that is contained
within an object. Also, the objects which you wish to explore and work
with don't necessarily need to be public, so you can, for example, set
the value of a private field of an object even if it's marked as
private!

For your specific question, the code is relatively simple. For
example:

public bool HasProperty(object control, string propertyName)
{
return control.GetType().GetProperty(propertyName) != null;
}

public bool HasEvent(object control, string eventName)
{
return control.GetType().GetEvent(eventName) != null;
}

So, for example, if you want to know if a control, has a property named
"Text", you'd simply do:

bool hasText = HasProperty(myControl, "Text");

If you want to know if it has an event called "Clicked":

bool hasClicked = HasProperty(myControl, "Clicked");
Hope this helps!

Brant Estes
Senior Consultant
Magenic Technologies


ABC wrote:
I am a newie about Reflection. I have not any ideas about Reflection
concept. May I have some tutorials or artists from internet? Any
recommandation?
"Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote in
message news:eSaA10AEGHA.2872@TK2MSFTNGP14.phx.gbl...
ABC,

You want to use Reflection for this. First, get the type of the object
through a call to GetType. Once you do this, you will want to call
GetProperties or GetEvents to get the properties or events.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

"ABC" <abc@abc.com> wrote in message
news:%23J5uNrAEGHA.984@tk2msftngp13.phx.gbl...
I want to check the form's controls have or not the specific properties or
events. How to determine or gather the properties list under the run-time
environment?



Jan 9 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.