How add attribute with enum to control?

Posted on 2009-04-06
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
  • 3
  • 2
LVL 29

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 29

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 29

Accepted Solution

anarki_jimbel earned 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Icons and Colors for Terms 3 24
C# HTTP GET method sample code 3 41
Help with C#, MVC, razor. 6 23
Where to download and how to install sqldmo.dll 5 34
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: (…

895 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

16 Experts available now in Live!

Get 1:1 Help Now