Newbie Enum properties

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to select the input style for my custom textbox to accept either only
letters, or digits, or both, as chosen at design time. How do I create an
enumeration that appears in the properties window so that I can select the
input style for different scenarios?

I'm fairly new to programming so any sample code would be most appreciated.
 
Hi,

You just have to add Browsable (true) at the begining of your method. Look
at this code for some UserControl:

public enum TestEnum
{
Choice1,
Choice2,
Choice3
}


private TestEnum myEnum = TestEnum.Choice1;

[Browsable(true)]
public new TestEnum MyProperty
{
get { return myEnum; }
set {myEnum = value; }
}


Hope this will help you.
 
Little error -- here's the correct code:

Browsable(true)]
public TestEnum MyProperty
{
get { return myEnum; }
set {myEnum = value; }
}
 
Peter,

Thanks for your help, but I'm still missing something.

I take it that I am to create 2 properties, one for noLetters and one for
noDigits, and assign the first one the value InputStyle.noLetters and the
other InputStyle.noDigits.

public enum InputStyle
{
noDigits,
noLetters
}


private InputStyle myEnum = TestEnum.noDigits;
private InputStyle myOtherEnum = TestEnum.noLetters;

[Browsable(true)]
public InputStyle MyProperty
{
get { return noLetters; }
set {noLetters = value; }
}
[Browsable(true)]
public InputStyle MyOtherProperty
{
get { return noDigits; }
set {noDigits = value; }
}

Doing that creates 2 properties with a drop down box with both choices.
I need to be able to create one property called InputStyle and have the
dropdown box offer the choices to the programmer.

I've played around with it a bit but can't get that functionality. Any help
on that point would be most appreciated.

Alan

Peter Jausovec said:
Little error -- here's the correct code:

Browsable(true)]
public TestEnum MyProperty
{
get { return myEnum; }
set {myEnum = value; }
}

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
cashdeskmac said:
I want to select the input style for my custom textbox to accept either
only
letters, or digits, or both, as chosen at design time. How do I create an
enumeration that appears in the properties window so that I can select the
input style for different scenarios?

I'm fairly new to programming so any sample code would be most
appreciated.
 
Alan,

Isn't it ok like this ? Where InputStyle is enum with 2 values (noDigits,
noLetters)..

public InputStyle MyInputStyle
{
get { return m_myInputStyle; }
set { m_myInputStyle = value; }
}


--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
cashdeskmac said:
Peter,

Thanks for your help, but I'm still missing something.

I take it that I am to create 2 properties, one for noLetters and one for
noDigits, and assign the first one the value InputStyle.noLetters and the
other InputStyle.noDigits.

public enum InputStyle
{
noDigits,
noLetters
}


private InputStyle myEnum = TestEnum.noDigits;
private InputStyle myOtherEnum = TestEnum.noLetters;

[Browsable(true)]
public InputStyle MyProperty
{
get { return noLetters; }
set {noLetters = value; }
}
[Browsable(true)]
public InputStyle MyOtherProperty
{
get { return noDigits; }
set {noDigits = value; }
}

Doing that creates 2 properties with a drop down box with both choices.
I need to be able to create one property called InputStyle and have the
dropdown box offer the choices to the programmer.

I've played around with it a bit but can't get that functionality. Any
help
on that point would be most appreciated.

Alan

Peter Jausovec said:
Little error -- here's the correct code:

Browsable(true)]
public TestEnum MyProperty
{
get { return myEnum; }
set {myEnum = value; }
}

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
cashdeskmac said:
I want to select the input style for my custom textbox to accept either
only
letters, or digits, or both, as chosen at design time. How do I create
an
enumeration that appears in the properties window so that I can select
the
input style for different scenarios?

I'm fairly new to programming so any sample code would be most
appreciated.
 
Thank you very much, Peter, got it now.


Peter Jausovec said:
Alan,

Isn't it ok like this ? Where InputStyle is enum with 2 values (noDigits,
noLetters)..

public InputStyle MyInputStyle
{
get { return m_myInputStyle; }
set { m_myInputStyle = value; }
}


--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
cashdeskmac said:
Peter,

Thanks for your help, but I'm still missing something.

I take it that I am to create 2 properties, one for noLetters and one for
noDigits, and assign the first one the value InputStyle.noLetters and the
other InputStyle.noDigits.

public enum InputStyle
{
noDigits,
noLetters
}


private InputStyle myEnum = TestEnum.noDigits;
private InputStyle myOtherEnum = TestEnum.noLetters;

[Browsable(true)]
public InputStyle MyProperty
{
get { return noLetters; }
set {noLetters = value; }
}
[Browsable(true)]
public InputStyle MyOtherProperty
{
get { return noDigits; }
set {noDigits = value; }
}

Doing that creates 2 properties with a drop down box with both choices.
I need to be able to create one property called InputStyle and have the
dropdown box offer the choices to the programmer.

I've played around with it a bit but can't get that functionality. Any
help
on that point would be most appreciated.

Alan

Peter Jausovec said:
Little error -- here's the correct code:

Browsable(true)]
public TestEnum MyProperty
{
get { return myEnum; }
set {myEnum = value; }
}

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
I want to select the input style for my custom textbox to accept either
only
letters, or digits, or both, as chosen at design time. How do I create
an
enumeration that appears in the properties window so that I can select
the
input style for different scenarios?

I'm fairly new to programming so any sample code would be most
appreciated.
 
Back
Top