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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity bundle 8 36
.net VBA word safemode 1 24
Need an intro to -- .Net SQL Authorization Manager 7 47
Visual Studio editor? 1 12
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.…
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

18 Experts available now in Live!

Get 1:1 Help Now