Solved

How add attribute with enum to control?

Posted on 2009-04-06
5
345 Views
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):

[SetProperty1(SomeClass.Enum3)]
class MyControl() : Control
{
  MyControl(){
    int attributeValue = passedInEnumValue;}
}

I'd like to do this for web and winform controls.
0
Comment
Question by:brettr
  • 3
  • 2
5 Comments
 
LVL 29

Expert Comment

by:anarki_jimbel
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

        {

            Enum1Item1, 

            Enum1Item2,

            Enum1Item3 

        }

    }
 

===================================
 

        public MyUserControl()

        {

            InitializeComponent();

            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

0
 
LVL 29

Expert Comment

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

Author Comment

by:brettr
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.
0
 
LVL 29

Accepted Solution

by:
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:
http://aspalliance.com/778_Attributes_and_Reflection_in_C

I'd choose another way...
0
 

Author Comment

by:brettr
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?
0

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
asp.net 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 (http://www.experts-exchange.com/M_6114203.html) 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