[Last Call] Learn how to a build a cloud-first strategyRegister Now


Mimic System.Drawing.Color

Posted on 2011-05-10
Medium Priority
Last Modified: 2012-05-11
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.
Question by:twcadmin
  • 2
  • 2
LVL 23

Assisted Solution

by:Jens Fiederer
Jens Fiederer earned 800 total points
ID: 35732343
Instead of making PageType a string, you can make it an enum, say of type PageTypes.

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

LVL 83

Accepted Solution

CodeCruiser earned 1200 total points
ID: 35732353
You can use an Enum

Public Enum MyPageTypes
End Enum

Author Comment

ID: 35732362
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

LVL 83

Expert Comment

ID: 35732365

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.

Author Comment

ID: 35746294
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month17 days, 17 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question