views:

1523

answers:

2

Hopefully some Custom Control Designers/Builders can help

I'm attempting to build my first custom control that is essential a client detail collection form. There are to be a series of elements to this form that require various styles applied to them. Ideally I'd like the VS 2005/2008 properties interface to be able to apply the CSSClass as it does at the control level, i.e. with a dropdown list of available CSS Clases.

Take for example the Class to be applied to the legend tag

/// <summary>Css Class for Legend</summary>
[Category("Appearance")]
[Browsable(true)]
[DefaultValue("")]
//I am at a loss as to what goes in [Editor]
[Editor(System.Web.UI.CssStyleCollection), typeof(System.Drawing.Design.UITypeEditor))]        
 public string LegendCSSClass
    {
        get { return _LegendCSSClass; }
        set { _LegendCSSClass = value; }
    }

I have tried a couple of options, as you can see from above, without much luck.

Hopefully there is something simple I am missing.

I'd also be happy for references pertaining to the

[Editor]
attribute

+1  A: 

Add the CssClassProperty attribute to your property.

[Category("Appearance")]
[Browsable(true)]
[DefaultValue("")]
[CssClassProperty]
public string LegendCSSClass    
{        
   get { return _LegendCSSClass; }        
   set { _LegendCSSClass = value; }    
}

From MSDN: Adds Cascading Style Sheet (CSS) editing capabilities to a property at design time.

BTW for this kind of question, Lutz Reflector is your friend. You can look at the attributes that are applied to similar properties in .NET Framework classes.

Joe
Thanks for the tip Joe. Though it hasn't appeared to have worked at this point. I'm still just getting a text entry option in VS. Deadline pressures are going to dictate that this will have to suffice for now. I;ll come back and review the issue later.
Jon P
A: 

For what ever reason this does not work for me:

public class MyLabel: Label
{

    private string _LegendCSSClass;

    [Category("Appearance")]
    [Browsable(true)]
    [DefaultValue("")] 
    [CssClassProperty]
    public string LegendCSSClass
    {
        get { return _LegendCSSClass; }
        set { _LegendCSSClass = value; }
    } 
}
Kai