⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 toolbardropdownlist.cs

📁 浏览器端看到树型目录结构,用户可以完整地看到像windows资源管理器一样的效果
💻 CS
📖 第 1 页 / 共 3 页
字号:
//------------------------------------------------------------------------------
// Copyright (c) 2000-2003 Microsoft Corporation. All Rights Reserved.
//------------------------------------------------------------------------------

namespace Microsoft.Web.UI.WebControls
{
    using System;
    using System.Collections;
    using System.Collections.Specialized;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
    using System.Drawing;
    using System.Globalization;
    using System.Reflection;

    /// <summary>
    /// Represents a dropdownlist in a toolbar.
    /// </summary>
    [
    ParseChildren(true, "Items"),
    PersistChildren(true),
    ]
    public class ToolbarDropDownList : ToolbarItem, IPostBackDataHandler
    {
        /// <summary>
        /// Fired when the SelectedIndex property changes.
        /// </summary>
        public event EventHandler SelectedIndexChanged;

        private InternalDropDownList _List;
        private CssWrapper _CssWrapper;
        private bool _IsTrackingVS;
        private string _HelperID;

        /// <summary>
        /// Initializes a new ToolbarDropDownList.
        /// </summary>
        public ToolbarDropDownList() : base()
        {
            _List = new InternalDropDownList();
            _List.SelectedIndexChanged += new EventHandler(this.OnSelectedIndexChanged);
            _IsTrackingVS = false;
            _HelperID = null;
        }

        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>A new object that is a copy of this instance.</returns>
        public override object Clone()
        {
            ToolbarDropDownList copy = (ToolbarDropDownList)base.Clone();

            copy.SelectedIndexChanged = this.SelectedIndexChanged;

            copy._List = new InternalDropDownList();
            if (this._IsTrackingVS)
            {
                ((IStateManager)copy).TrackViewState();
            }

            foreach (ListItem item in this._List.Items)
            {
                ListItem newItem = new ListItem(item.Text, item.Value);
                if (item.Selected)
                {
                    newItem.Selected = true;
                }

                copy._List.Items.Add(newItem);
            }

            foreach (string key in this._List.Attributes.Keys)
            {
                copy._List.Attributes.Add(key, this._List.Attributes[key]);
            }

            foreach (string key in this._List.VS.Keys)
            {
                PropertyInfo pinfo = copy._List.GetType().GetProperty(key);
                if ((pinfo != null) && pinfo.CanRead && pinfo.CanWrite)
                {
                    // Try to be more gentle
                    object obj = pinfo.GetValue(this._List, null);
                    pinfo.SetValue(copy._List, obj, null);
                }
                else
                {
                    // Brute force copy the ViewState
                    object obj = this._List.VS[key];
                    if (obj is ICloneable)
                    {
                        obj = ((ICloneable)obj).Clone();
                    }
                    copy._List.VS[key] = obj;
                }
            }

            copy._List.Font.CopyFrom(this._List.Font);

            return copy;
        }

        /// <summary>
        /// Sets all items within the StateBag to be dirty
        /// </summary>
        protected internal override void SetViewStateDirty()
        {
            base.SetViewStateDirty();

            Hashtable table = new Hashtable();
            foreach (string key in _List.Attributes.Keys)
            {
                table[key] = _List.Attributes[key];
            }
            _List.Attributes.Clear();
            foreach (string key in table.Keys)
            {
                _List.Attributes[key] = (string)table[key];
            }

            foreach (string key in _List.VS.Keys)
            {
                PropertyInfo pinfo = _List.GetType().GetProperty(key);
                if ((pinfo != null) && pinfo.CanRead && pinfo.CanWrite)
                {
                    object obj = pinfo.GetValue(_List, null);
                    pinfo.SetValue(_List, obj, null);
                }
            }

            _List.Font.CopyFrom(_List.Font);

            foreach (StateItem item in _List.VS.Values)
            {
                item.IsDirty = true;
            }
        }

        /// <summary>
        /// Fires the SelectedIndexChanged event.
        /// </summary>
        /// <param name="sender">Source object.</param>
        /// <param name="e">Event arguments.</param>
        protected virtual void OnSelectedIndexChanged(Object sender, EventArgs e)
        {
            if (SelectedIndexChanged != null)
            {
                SelectedIndexChanged(this, e);   // call the delegate
            }
        }

        /// <summary>
        /// Gets a collection of text attributes that will be rendered as a style attribute on the outer tag.
        /// </summary>
        [
        Browsable(false),
        DefaultValue(typeof(CssCollection), ""),
        PersistenceMode(PersistenceMode.Attribute),
        ResDescription("InnerControlStyle"),
        ]
        public CssCollection Style 
        {
            get
            {
                if (_CssWrapper == null)
                {
                    _CssWrapper = new CssWrapper(_List);
                }

                return _CssWrapper;
            }
            set
            {
                CssCollection style = this.Style;
                style.Clear();
                style.Merge(value, true);
            }
        }

        /// <summary>
        /// Gets the style of the control
        /// </summary>
        [
        Browsable(false),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
        ]
        public Style ControlStyle
        {
            get { return _List.ControlStyle; }
        }

        /// <summary>
        /// Gets or sets the background color of the Web control.
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(typeof(Color), ""),
        TypeConverterAttribute(typeof(WebColorConverter)),
        ResDescription("InnerControlBackColor"),
        ]
        public virtual Color BackColor 
        {
            get { return _List.BackColor; }
            set { _List.BackColor = value; }
        }

        // We've chosen not to support certain attributes which have been "pound-if'd out"
#if false
        /// <summary>
        /// Gets or sets the border color of the Web control.
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(typeof(Color), ""),
        TypeConverterAttribute(typeof(WebColorConverter)),
        ResDescription("InnerControlBorderColor"),
        ]
        public virtual Color BorderColor 
        {
            get { return _List.BorderColor; }
            set { _List.BorderColor = value; }
        }

        /// <summary>
        /// Gets or sets the border width of the Web control.
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(typeof(Unit), ""),
        ResDescription("InnerControlBorderWidth"),
        ]
        public virtual Unit BorderWidth 
        {
            get { return _List.BorderWidth; }
            set { _List.BorderWidth = value; }
        }

        /// <summary>
        /// Gets or sets the border style of the Web control.
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(BorderStyle.NotSet),
        ResDescription("InnerControlBorderStyle"),
        ]
        public virtual BorderStyle BorderStyle 
        {
            get { return _List.BorderStyle; }
            set { _List.BorderStyle = value; }
        }
#endif

        /// <summary>
        /// Gets or sets the CssClass
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(""),
        ResDescription("InnerControlCssClass"),
        ]
        public virtual string CssClass 
        {
            get { return _List.CssClass; }
            set { _List.CssClass = value; }
        }

        /// <summary>
        /// Gets font information
        /// </summary>
        [
        Category("Appearance"),
        DefaultValue(null),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
        NotifyParentProperty(true),
        ResDescription("InnerControlFont"),
        ]
        public virtual FontInfo Font 
        {
            get { return _List.Font; }
        }

        /// <summary>
        /// Gets or sets the foreground color (typically the color of the text) of the control
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(typeof(Color), ""),
        TypeConverterAttribute(typeof(WebColorConverter)),
        ResDescription("InnerControlForeColor"),
        ]
        public virtual Color ForeColor 
        {
            get { return _List.ForeColor; }
            set { _List.ForeColor = value; }
        }

#if false
        /// <summary>
        /// The height of the control
        /// </summary>
        [
        Bindable(true),
        Category("Layout"),
        DefaultValue(typeof(Unit), ""),
        ResDescription("InnerControlHeight"),
        ]
        public virtual Unit Height 
        {
            get { return _List.Height; }
            set { _List.Height = value; }
        }
#endif

        /// <summary>
        /// The Width of the control
        /// </summary>
        [
        Bindable(true),
        Category("Layout"),
        DefaultValue(typeof(Unit), ""),
        ResDescription("InnerControlWidth"),
        ]
        public virtual Unit Width
        {
            get { return _List.Width; }
            set { _List.Width = value; }
        }

        /// <summary>
        /// Gets or sets a value indicating whether the state automatically posts back to the server when clicked.
        /// </summary>
        [
        Category("Behavior"),
        DefaultValue(false),
        PersistenceMode(PersistenceMode.Attribute),
        ResDescription("AutoPostBack"),
        ]
        public virtual bool AutoPostBack
        {
            get
            {
                // If the AutoPostBack property has been set,
                // then retrieve it.
                if (ViewState["AutoPostBack"] != null)
                {
                    return _List.AutoPostBack;
                }

                // The AutoPostBack property has not been set,
                // so look to the parent
                Toolbar tbParent = ParentToolbar;
                if (tbParent != null)
                {
                    return tbParent.AutoPostBack;
                }

                return false;
            }

            set
            {

⌨️ 快捷键说明

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