Link to home
Start Free TrialLog in
Avatar of twcadmin
twcadmin

asked on

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.
SOLUTION
Avatar of Jens Fiederer
Jens Fiederer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of twcadmin
twcadmin

ASKER

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

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