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.
LVL 5
twcadminAsked:
Who is Participating?
 
CodeCruiserCommented:
You can use an Enum

Public Enum MyPageTypes
HomePage
AdminPage
UserPage
...
End Enum
0
 
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};

0
 
twcadminAuthor Commented:
I search before posting and finally found the answer as soon as I posted. Found the answer here
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/5dcb5832-bcba-4f3b-a892-1f7c25541cef/

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
  Get
   Return New Person("Billy")
  End Get
 End Property
 Public Shared ReadOnly Property Sally() As Person
  Get
   Return New Person("Sally")
  End Get
 End Property

End Structure

Open in new window

0
 
CodeCruiserCommented:
Oops.

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.
0
 
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
0
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.