Mimic System.Drawing.Color

Posted on 2011-05-10
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
    LVL 23

    Assisted Solution

    by:Jens Fiederer
    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

    You can use an Enum

    Public Enum MyPageTypes
    End Enum
    LVL 5

    Author Comment

    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


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

    Author Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now