Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


How add attribute with enum to control?

Posted on 2009-04-06
Medium Priority
Last Modified: 2012-05-06
How do I add an attribute to a custom control that takes an enum as its argument.  For example (in psuedo code):

class MyControl() : Control
    int attributeValue = passedInEnumValue;}

I'd like to do this for web and winform controls.
Question by:brettr
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 30

Expert Comment

ID: 24083540
Shouldn't be a problem. See my example for a very primitive control. After I build a solution I can drag the control from the toolbox onto my form. In the properties window I can see the property MyCustomProperty and all enumm members in a dropdown list.

    public class MyEnums
        public enum Enum1
        public MyUserControl()
            this.BorderStyle = BorderStyle.FixedSingle;
            this.BackColor = System.Drawing.Color.Red;
        private MyEnums.Enum1 _customProp;
        public MyEnums.Enum1 CustomProperty
            get { return _customProp; }
            set { _customProp = value; }

Open in new window

LVL 30

Expert Comment

ID: 24083548
if this is not what you want - explain what do you need this attribute for?

Author Comment

ID: 24083793
I need an attribute because a designer will rarely be used.

I want to provide the control with a role.  It will then decide to show/hide based on the user being in that role.
LVL 30

Accepted Solution

anarki_jimbel earned 2000 total points
ID: 24084042
Hmmm... Don't think there is anatrribute you need. Still, you may try to create a custom one:

I'd choose another way...

Author Comment

ID: 24084086
Yes - that's a bit involved just for an attribute.

I could overload the constructor and pass in the role value, since the control may not use roles in some cases.  But if it does, the call will supply it via a constructor.  Is there a better way for this?

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

636 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