More newbie enum problems

G

Guest

I have the following code to create a property for a custom control:

public enum InputStyle {NoLetters, NoDigits, ValidateEmail};
private InputStyle nNoLetters = InputStyle.NoLetters;
private InputStyle nNoDigits = InputStyle.NoDigits;
private InputStyle nValidateEmail = InputStyle.ValidateEmail;
[Browsable(true)]
public InputStyle NoLetters
{
set{nNoLetters = value;}
get{return nNoLetters;}
}
[Browsable(true)]
public InputStyle NoDigits
{
set{nNoDigits = value;}
get{return nNoDigits;}
}
[Browsable(true)]
public InputStyle ValidateEmail
{
set{nValidateEmail = value;}
get{return nValidateEmail;}
}

However, this gives me 3 properties and each has a dropdownlist with all 3
properties listed. I also have this eventhandler:

private void TextBoxEnum_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
if(NoDigits == InputStyle.NoDigits )
{
if(Char.IsDigit(e.KeyChar) ==true)
e.Handled = true;
}
else if(NoLetters == InputStyle.NoLetters)
{
if(Char.IsLetter(e.KeyChar) == true)
e.Handled = true;
}
}

Can anyone please tell me how to show just one property in the properties
window named InputStyle and have a dropdownlist with the 3 options for the
programmer to choose from.
 
L

Liam McNamara

You should only use one variable for the Enum:

public enum InputStyle {NoLetters, NoDigits, ValidateEmail};
private InputStyle style;

[Browsable(true)]
public InputStyle Style
{
set{ style = value;}
get{return style;}
}

private void TextBoxEnum_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
if(style == InputStyle.NoDigits)
{
}
else if(style == InputStyle.NoLetters)
{
}
else if(style == InputStyle.ValidateEmail)
{
}
}

or use a case statement:

switch(style)
{
case InputStyle.NoDigits: ... break;
case InputStyule.NoLetters:...

--Liam.
 
G

Guest

Having sorted all of that out, I find that I set the property to NoDigits and
run the app, it works fine. However, when I add other controls to the form
and run it again, it defaults to NoLetters. I have to set the property
everytime I run in debug mode. Will this change when I release the app?
 
L

Liam McNamara

When you say "set the property" do you mean that you're setting the property
in your form's constructor (this.style = InputStyle.NoDigits) and it is
changing later on, or you are setting it in designer and it changes when you
run the app?

--Liam.

cashdeskmac said:
Having sorted all of that out, I find that I set the property to NoDigits and
run the app, it works fine. However, when I add other controls to the form
and run it again, it defaults to NoLetters. I have to set the property
everytime I run in debug mode. Will this change when I release the app?

cashdeskmac said:
I have the following code to create a property for a custom control:

public enum InputStyle {NoLetters, NoDigits, ValidateEmail};
private InputStyle nNoLetters = InputStyle.NoLetters;
private InputStyle nNoDigits = InputStyle.NoDigits;
private InputStyle nValidateEmail = InputStyle.ValidateEmail;
[Browsable(true)]
public InputStyle NoLetters
{
set{nNoLetters = value;}
get{return nNoLetters;}
}
[Browsable(true)]
public InputStyle NoDigits
{
set{nNoDigits = value;}
get{return nNoDigits;}
}
[Browsable(true)]
public InputStyle ValidateEmail
{
set{nValidateEmail = value;}
get{return nValidateEmail;}
}

However, this gives me 3 properties and each has a dropdownlist with all 3
properties listed. I also have this eventhandler:

private void TextBoxEnum_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
if(NoDigits == InputStyle.NoDigits )
{
if(Char.IsDigit(e.KeyChar) ==true)
e.Handled = true;
}
else if(NoLetters == InputStyle.NoLetters)
{
if(Char.IsLetter(e.KeyChar) == true)
e.Handled = true;
}
}

Can anyone please tell me how to show just one property in the propertie s
window named InputStyle and have a dropdownlist with the 3 options for the
programmer to choose from.
 
G

Guest

Liam,

I haven't set the property in the constructor, I selected it from the
properties window and chose NoDigits. I then ran the program, stopped it,
added a label, and when I started it again, the property had defaulted to the
NoLetters option.

Liam McNamara said:
When you say "set the property" do you mean that you're setting the property
in your form's constructor (this.style = InputStyle.NoDigits) and it is
changing later on, or you are setting it in designer and it changes when you
run the app?

--Liam.

cashdeskmac said:
Having sorted all of that out, I find that I set the property to NoDigits and
run the app, it works fine. However, when I add other controls to the form
and run it again, it defaults to NoLetters. I have to set the property
everytime I run in debug mode. Will this change when I release the app?

cashdeskmac said:
I have the following code to create a property for a custom control:

public enum InputStyle {NoLetters, NoDigits, ValidateEmail};
private InputStyle nNoLetters = InputStyle.NoLetters;
private InputStyle nNoDigits = InputStyle.NoDigits;
private InputStyle nValidateEmail = InputStyle.ValidateEmail;
[Browsable(true)]
public InputStyle NoLetters
{
set{nNoLetters = value;}
get{return nNoLetters;}
}
[Browsable(true)]
public InputStyle NoDigits
{
set{nNoDigits = value;}
get{return nNoDigits;}
}
[Browsable(true)]
public InputStyle ValidateEmail
{
set{nValidateEmail = value;}
get{return nValidateEmail;}
}

However, this gives me 3 properties and each has a dropdownlist with all 3
properties listed. I also have this eventhandler:

private void TextBoxEnum_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
if(NoDigits == InputStyle.NoDigits )
{
if(Char.IsDigit(e.KeyChar) ==true)
e.Handled = true;
}
else if(NoLetters == InputStyle.NoLetters)
{
if(Char.IsLetter(e.KeyChar) == true)
e.Handled = true;
}
}

Can anyone please tell me how to show just one property in the propertie s
window named InputStyle and have a dropdownlist with the 3 options for the
programmer to choose from.
 
L

Liam McNamara

When you set the property in designer it puts code into InitializeComponent,
take a look at the generated code and see if your designer values are set
there, if they are then you are either assigning the control to a new
instance or they are changed elsewhere in the code.

Do a search for <controlInstance>.<Property> in your code, or just look for
all references to <controlInstance>.

--Liam.

cashdeskmac said:
Liam,

I haven't set the property in the constructor, I selected it from the
properties window and chose NoDigits. I then ran the program, stopped it,
added a label, and when I started it again, the property had defaulted to the
NoLetters option.

Liam McNamara said:
When you say "set the property" do you mean that you're setting the property
in your form's constructor (this.style = InputStyle.NoDigits) and it is
changing later on, or you are setting it in designer and it changes when you
run the app?

--Liam.

cashdeskmac said:
Having sorted all of that out, I find that I set the property to
NoDigits
and
run the app, it works fine. However, when I add other controls to the form
and run it again, it defaults to NoLetters. I have to set the property
everytime I run in debug mode. Will this change when I release the app?

:

I have the following code to create a property for a custom control:

public enum InputStyle {NoLetters, NoDigits, ValidateEmail};
private InputStyle nNoLetters = InputStyle.NoLetters;
private InputStyle nNoDigits = InputStyle.NoDigits;
private InputStyle nValidateEmail = InputStyle.ValidateEmail;
[Browsable(true)]
public InputStyle NoLetters
{
set{nNoLetters = value;}
get{return nNoLetters;}
}
[Browsable(true)]
public InputStyle NoDigits
{
set{nNoDigits = value;}
get{return nNoDigits;}
}
[Browsable(true)]
public InputStyle ValidateEmail
{
set{nValidateEmail = value;}
get{return nValidateEmail;}
}

However, this gives me 3 properties and each has a dropdownlist with
all
3
properties listed. I also have this eventhandler:

private void TextBoxEnum_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
if(NoDigits == InputStyle.NoDigits )
{
if(Char.IsDigit(e.KeyChar) ==true)
e.Handled = true;
}
else if(NoLetters == InputStyle.NoLetters)
{
if(Char.IsLetter(e.KeyChar) == true)
e.Handled = true;
}
}

Can anyone please tell me how to show just one property in the
propertie
s
window named InputStyle and have a dropdownlist with the 3 options
for
the
programmer to choose from.
 

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