我主加了一个控件发生MyColor只能输入文本
怎么做成VS控件一样的可以选颜色谢谢

解决方案 »

  1.   

    [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]   
    public Color xxx
    {
    get{}
    set{}
    }
      

  2.   

    具体可以参考这个
    private Color _bgColor=new Color();
    [DefaultValue("White"),Description("背景颜色"),Category("Appearance")] 
    public Color BgColor
    {
    get 
    {
    return _bgColor;
    }
    set 
    {
    _bgColor=value;
    }
    }
      

  3.   

    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
    using System.Drawing;
    namespace WebControlLibrary1
    {
    /// <summary>
    /// WebCustomControl1 的摘要说明。
    /// </summary>
    [DefaultProperty("MyText"),
    ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
    public class WebCustomControl1 : System.Web.UI.WebControls.Label
    {
    private Color backColor;//背景色 [Bindable(true),Description("设定按钮渐变的背景色"),Category("Appearance")]
    public Color MyBackGroundColor { get { return backColor; } set { backColor=value; } } /// <summary>
    /// 将此控件呈现给指定的输出参数。
    /// </summary>
    /// <param name="output"> 要写出到的 HTML 编写器 </param>
    protected override void Render(HtmlTextWriter output)
    {
    this.BackColor = MyBackGroundColor;
    base.Render(output); }
    }
    }