Properties and enum C#

T

Tron

I have a question and before everithing thanks for reading. I have a
custon control in windows forms and i want to expose a property with
enum values. i have three values and i want that property takes those
values from the list. Can anybody help me in this topic? I'm kind of
new in this topic of windows forms and user controls.

thanks in advance
Tron Mexique
 
M

Marcos Stefanakopolus

Tron said:
I have a question and before everithing thanks for reading. I have a
custon control in windows forms and i want to expose a property with
enum values. i have three values and i want that property takes those
values from the list. Can anybody help me in this topic? I'm kind of
new in this topic of windows forms and user controls.

If you want the enumeration to be visible everywhere in your namespace,
you'd do something like:

namespace myApplication {

public enum myEnum {
valueOne,
valueTwo,
valueThree;
}

public class myClass {
private myEnum _EnumValue;
public myEnum EnumValue {
get { return _EnumValue; }
set { _EnumValue = value; }
}
// .. you fill in the class constructor and stuff...
}

}

If you want the enumeration to be explicitly attached to the class that is
exposing it as a property, then just move the definition of the enumeration
inside of the class (leave it public), but then be aware that elsewhere in
your program you'll have to refer to those values as
"myClass.myEnum.valueOne" rather than just "myEnum.valueOne".
 

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

Top