生成两个控件属性

来源:互联网 发布:打击网络犯罪工作总结 编辑:程序博客网 时间:2024/06/07 09:15

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ServerControl1
{
    public class ImageLabel2 : Label
    {
        [BrowsableAttribute(true)]
        [DescriptionAttribute("背景")]
        [CategoryAttribute("Appearance")]
        public virtual String ImageUrl
        {
            get { return ViewState["imageUrl"] != null ? (string)ViewState["imageUrl"] : ""; }
            set { ViewState["imageUrl"] = value; }
        }
        [BrowsableAttribute(true)]
        [DescriptionAttribute("背景")]
        [CategoryAttribute("Appearance")]
        public virtual String TestAlign
        {
            get { return ViewState["TestAlign"] != null ? (string)ViewState["TestAlign"] : ""; }
            set { ViewState["TestAlign"] = value; }
        }
        override protected void AddAttributesToRender(HtmlTextWriter writer)
        {
            writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundImage, ImageUrl);

            writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor,TestAlign);
            base.AddAttributesToRender(writer);
        }
    }
}

 BrowsableAttribute   是否在控件属性窗口中显示

 [CategoryAttribute("Appearance")]    此属性为在属性窗口的哪个分类中显示