Mimic System.Drawing.Color

I'm trying to mimic System.Drawing.Color in that I want to have a class that can return different acceptable values. I have a custom web control and one of the properties that the user can set is PageType. I keep forgetting the values that the control has stored so I want to be able to do something like        

MyControl.PageType = CustomPageTypes.HomePage

Right now I do MyControl.PageType = "HomePage" to pass a string as the value but I want to be able to mimic System.Drawing.Color  (e.g. for red you can assign System.Drawing.Color.Red)

Working in VB.NET but C# is also acceptable.
Who is Participating?
You can use an Enum

Public Enum MyPageTypes
End Enum
Jens FiedererTest Developer/ValidatorCommented:
Instead of making PageType a string, you can make it an enum, say of type PageTypes.

enum PageTypes { BigPage, LittlePage, StrongPage, WeakPage};

twcadminAuthor Commented:
I search before posting and finally found the answer as soon as I posted. Found the answer here

Code below where Person is actually what i'm trying to refer to as CustomPageTypes
and the properties that are currently set as names would be renamed as my page types (e.g. HomePage)
Public Structure Person

 'As Friend scope this can be used by internal assemby classes
 'much like Color does within the Drawing namespace classes.
 Friend Name As String

 Private Sub New(ByVal _name As String)
  Name = _name
 End Sub

 Public Overrides Function ToString() As String
  Return Name
 End Function

 Public Shared ReadOnly Property Billy() As Person
   Return New Person("Billy")
  End Get
 End Property
 Public Shared ReadOnly Property Sally() As Person
   Return New Person("Sally")
  End Get
 End Property

End Structure

Open in new window


Then set the type of PageType to this enum.

If you are using C# then jensfiederer's example would work. If VB.NET then mine.
twcadminAuthor Commented:
Althought both methods can work in different ways, I revoke my choice of using Structure since the experts suggestions of using Enum was the ultimate solution to my problem and I am now using Enum
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.