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

📄 toolbartextbox.cs

📁 浏览器端看到树型目录结构,用户可以完整地看到像windows资源管理器一样的效果
💻 CS
📖 第 1 页 / 共 3 页
字号:
                    }
                    style += names[i];
                }
                style += ";";
            }

            FontUnit fu = font.Size;
            if (!fu.IsEmpty)
            {
                style += "font-size:" + fu.ToString(CultureInfo.InvariantCulture) + ";";
            }

            if (font.Bold)
            {
                style += "font-weight:bold;";
            }
            if (font.Italic)
            {
                style += "font-style:italic;";
            }

            bool underline = font.Underline;
            bool overline = font.Overline;
            bool strikeout = font.Strikeout;
            string td = String.Empty;

            if (underline)
                td = "underline";
            if (overline)
                td += " overline";
            if (strikeout)
                td += " line-through";
            if (td.Length > 0)
                style += "text-decoration:" + td + ";";

            unit = Height;
            if (!unit.IsEmpty)
            {
                style += "height:" + unit.ToString(CultureInfo.InvariantCulture) + ";";
            }

            unit = Width;
            if (!unit.IsEmpty)
            {
                style += "width:" + unit.ToString(CultureInfo.InvariantCulture) + ";";
            }

            style += Style.CssText;

            writer.WriteAttribute("style", style);

            writer.WriteAttribute("type", (TextMode == ToolbarTextBoxMode.Password) ? "password" : "text");

            if (Columns > 0)
            {
                writer.WriteAttribute("size", Columns.ToString());
            }
            if (MaxLength > 0)
            {
                writer.WriteAttribute("maxlength", MaxLength.ToString());
            }
            if (ReadOnly)
            {
                writer.WriteAttribute("readonly", ReadOnly.ToString());
            }
            if ((Text != String.Empty) && (TextMode != ToolbarTextBoxMode.Password))
            {
                writer.WriteAttribute("value", Text, true);
            }

            if (Enabled)
            {
                writer.WriteAttribute("onpropertychange", "window.document.all." + HelperID + ".value=value");
                writer.WriteAttribute("onchange", "window.document.all." + HelperID + ".value=" + ParentToolbar.ClientID + ".getItem(" + Index + ").getAttribute('value')");
                writer.WriteAttribute("onkeyup", "window.document.all." + HelperID + ".value=" + ParentToolbar.ClientID + ".getItem(" + Index + ").getAttribute('value')");
            }
            else
            {
                writer.WriteAttribute("disabled", "true");
            }

            Toolbar parent = ParentToolbar;
            string script = "if (event.keyCode==13){event.returnValue=false;";
            if (Enabled && (parent != null) && (parent.Page != null))
            {
                string postBackRef = "if (" + parent.ClientID + ".getAttribute('_submitting') == null){" + parent.ClientID + ".setAttribute('_submitting', 'true');window.setTimeout('" + parent.Page.GetPostBackEventReference(_TextBox).Replace("'", "\\'") + "', 0, 'JScript');}";
                if (AutoPostBack)
                {
                    // Blur will cause a postback when AutoPostBack is true
                    script += "blur();";

                    // Add the blur postback handler
                    writer.WriteAttribute("_origVal", (TextMode != ToolbarTextBoxMode.Password) ? Text : String.Empty, true);
                    writer.WriteAttribute("onblur", "JScript:if (value != _origVal)" + postBackRef);
                }
                else
                {
                    // Do the postback
                    script += postBackRef + ";";
                }
            }
            script += "}";
            writer.WriteAttribute("onkeydown", script);
        }

        /// <summary>
        /// Renders the item's contents.
        /// </summary>
        /// <param name="inlineWriter">The HtmlTextWriter object that receives the content.</param>
        protected override void DownLevelContent(HtmlTextWriter inlineWriter)
        {
            HtmlTextWriter writer = (HtmlTextWriter)inlineWriter.InnerWriter;

            Toolbar parent = ParentToolbar;
            if (Enabled && AutoPostBack && (parent != null) && (parent.Page != null))
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Onchange, parent.Page.GetPostBackEventReference(_TextBox));
            }

            // Inherit the current font
            if (Font.Names.Length == 0)
            {
                string font = CurrentStyle["font"];
                string fontFamily = CurrentStyle["font-family"];
                string fontSize = CurrentStyle["font-size"];
                string fontWeight = CurrentStyle["font-weight"];
                string fontStyle = CurrentStyle["font-style"];

                if (font != null)
                {
                    _TextBox.Style["font"] = font;
                }
                if (fontFamily != null)
                {
                    _TextBox.Style["font-family"] = fontFamily;
                }
                if (fontSize != null)
                {
                    _TextBox.Style["font-size"] = fontSize;
                }
                if (fontWeight != null)
                {
                    _TextBox.Style["font-weight"] = fontWeight;
                }
                if (fontStyle != null)
                {
                    _TextBox.Style["font-style"] = fontStyle;
                }
            }

            _TextBox.RenderControl(writer);
        }

        /// <summary>
        /// Renders the item's contents.
        /// </summary>
        /// <param name="writer">The HtmlTextWriter object that receives the content.</param>
        protected override void DesignerContent(HtmlTextWriter writer)
        {
            bool UndoFont = false;
            bool UndoFontFamily = false;
            bool UndoFontSize = false;
            bool UndoFontWeight = false;
            bool UndoFontStyle = false;

            if (Font.Names.Length == 0)
            {
                string font = CurrentStyle["font"];
                string fontFamily = CurrentStyle["font-family"];
                string fontSize = CurrentStyle["font-size"];
                string fontWeight = CurrentStyle["font-weight"];
                string fontStyle = CurrentStyle["font-style"];

                if ((font != null) && (_TextBox.Style["font"] == null))
                {
                    _TextBox.Style["font"] = font;
                    UndoFont = true;
                }
                if ((fontFamily != null) && (_TextBox.Style["font-family"] == null))
                {
                    _TextBox.Style["font-family"] = fontFamily;
                    UndoFontFamily = true;
                }
                if ((fontSize != null) && (_TextBox.Style["font-size"] == null))
                {
                    _TextBox.Style["font-size"] = fontSize;
                    UndoFontSize = true;
                }
                if ((fontWeight != null) && (_TextBox.Style["font-weight"] == null))
                {
                    _TextBox.Style["font-weight"] = fontWeight;
                    UndoFontWeight = true;
                }
                if ((fontStyle != null) && (_TextBox.Style["font-style"] == null))
                {
                    _TextBox.Style["font-style"] = fontStyle;
                    UndoFontStyle = true;
                }
            }

            _TextBox.RenderControl(writer);

            if (UndoFont)
            {
                _TextBox.Style.Remove("font");
            }
            if (UndoFontFamily)
            {
                _TextBox.Style.Remove("font-family");
            }
            if (UndoFontSize)
            {
                _TextBox.Style.Remove("font-size");
            }
            if (UndoFontWeight)
            {
                _TextBox.Style.Remove("font-weight");
            }
            if (UndoFontStyle)
            {
                _TextBox.Style.Remove("font-style");
            }
        }

        /// <summary>
        /// Saves the item's state.
        /// </summary>
        /// <returns>The saved state.</returns>
        protected override object SaveViewState()
        {
            object state = base.SaveViewState();
            object textBox = _TextBox.SaveVS();

            if ((state != null) || (textBox != null))
            {
                return new object[] {state, textBox};
            }

            return null;
        }

        /// <summary>
        /// Loads the item's previously saved view state.
        /// </summary>
        /// <param name="savedState">An Object that contains the saved view state values for the item.</param>
        protected override void LoadViewState(object savedState)
        {
            if (savedState == null)
            {
                return;
            }

            object[] state = (object[])savedState;

            if (state[0] != null)
            {
                base.LoadViewState(state[0]);
            }
            if (state[1] != null)
            {
                _TextBox.LoadVS(state[1]);
            }
        }

        /// <summary>
        /// Tracks changes to the ViewState
        /// </summary>
        protected override void TrackViewState()
        {
            base.TrackViewState();

            _TextBox.TrackVS();
            _IsTrackingVS = true;
        }
    }

    /// <summary>
    /// The possible values for the TextMode property of the ToolbarTextBox.
    /// </summary>
    public enum ToolbarTextBoxMode
    {
        /// <summary>
        /// Single-line entry mode.
        /// </summary>
        SingleLine,

        /// <summary>
        /// Password entry mode.
        /// </summary>
        Password,
    };

    /// <summary>
    /// Internal TextBox class to give us access to certain methods
    /// </summary>
    internal class InternalTextBox : TextBox
    {
        /// <summary>
        /// Internal access to ViewState
        /// </summary>
        internal StateBag VS
        {
            get { return ViewState; }
        }

        /// <summary>
        /// TrackViewState
        /// </summary>
        internal void TrackVS()
        {
            TrackViewState();
        }

        /// <summary>
        /// SaveViewState
        /// </summary>
        /// <returns></returns>
        internal object SaveVS()
        {
            return SaveViewState();
        }

        /// <summary>
        /// LoadViewState
        /// </summary>
        /// <param name="state">State object</param>
        internal void LoadVS(object state)
        {
            LoadViewState(state);
        }
    }
}

⌨️ 快捷键说明

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