wtptoolbarcontainer.cs

来自「C#编写的在线用户统计、在线编辑器、验证码图片」· CS 代码 · 共 106 行

CS
106
字号
/*
 * WtpToolbarContainer.cs @Microsoft Visual Studio 2008 <.NET Framework 2.0 (or Higher)>
 * AfritXia
 * 2008/3/19
 *
 * Copyright(c) http://www.AfritXia.NET/
 *
 */

using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace Net.AfritXia.Web.UI
{
    /// <summary>
    /// 工具条容器控件
    /// </summary>
    [ParseChildren(false)]
    [ControlBuilder(typeof(WtpToolbarContainerCtrlBuilder))]
    public class WtpToolbarContainer : HtmlGenericControl, INamingContainer
    {
        // 工具条集合
        private List<WtpToolbarBase> m_toolbarItemList = null;

        #region 类构造器
        /// <summary>
        /// 类默认构造器
        /// </summary>
        public WtpToolbarContainer()
            : this("ToolbarContainer")
        {
        }

        /// <summary>
        /// 类参数构造器
        /// </summary>
        /// <param name="tagName">标记名称</param>
        public WtpToolbarContainer(string tagName)
            : base("div")
        {
            this.m_toolbarItemList = new List<WtpToolbarBase>();
        }
        #endregion

        /// <summary>
        /// 添加子控件
        /// </summary>
        /// <param name="obj"></param>
        protected override void AddParsedSubObject(object obj)
        {
            if (obj == null)
                return;

            if ((obj is LiteralControl) == true)
            {
                string text = null;
                
                // 获取控件文本
                text = ((LiteralControl)obj).Text;
                text = text.Trim();

                if (String.IsNullOrEmpty(text.Trim()) == false)
                    throw new Exception("无效的子控件类型 ( Invalid Type of Child Control )");

                return;
            }

            if ((obj is WtpToolbarBase) == false)
                throw new Exception("工具条必须是继承自 WtpToolbarBase ( Toolbar Must Inherit Class 'WtpToolbarBase' )");

            base.AddParsedSubObject(obj);
            this.m_toolbarItemList.Add((WtpToolbarBase)obj);
        }

        /// <summary>
        /// 添加工具条
        /// </summary>
        /// <param name="toolbar"></param>
        public void AddToolbar(WtpToolbarBase toolbar)
        {
            this.AddParsedSubObject(toolbar);
        }

        /// <summary>
        /// 清除所有的工具条
        /// </summary>
        public void ClearToolbar()
        {
            this.m_toolbarItemList.Clear();
            this.Controls.Clear();
        }

        /// <summary>
        /// 获取工具条项目集合
        /// </summary>
        public IList<WtpToolbarBase> ToolbarItemList
        {
            get
            {
                return this.m_toolbarItemList.AsReadOnly();
            }
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?