闪客动漫天地论坛

首页 » 设计乐园 » 彩信制作乐园 » 续:本论坛重写TextBox的功能
女女 - 2007-6-19 11:01:00
[Bindable(true), Category("Appearance"), DefaultValue("")]
        public string SetFocusButtonID
        {
            get
            {
                object o = ViewState[this.ClientID + "_SetFocusButtonID"];
                return (o == null) ? "" : o.ToString();
            }
            set
            {
                ViewState[this.ClientID + "_SetFocusButtonID"] = value;
                if (value != "")
                {
                    tb.Attributes.Add("onkeydown", "if(event.keyCode==13){document.getElementById('" + value + "').focus();}");
                }
            }
        }

        [Bindable(true), Category("Appearance"), DefaultValue("")]
        public override string ID
        {
            get
            {
                return tb.ID;
            }
            set
            {
                tb.ID = value;
            }
        }


        //调控件的最大长度属性
        [Bindable(true), Category("Appearance"), DefaultValue("")]
        public int MaxLength
        {
            get
            {
                object o = ViewState["TextBox_MaxLength"];
                if (o != null)
                {
                    int maxlength = Convert.ToInt32(o.ToString());
                    AddAttributes("maxlength", maxlength.ToString());
                    return maxlength;
                }
                else
                {
                    return -1;
                }
            }
            set
            {
                ViewState["TextBox_MaxLength"] = value;
                AddAttributes("maxlength", value.ToString());
            }
        }


        //调控件的TextMode属性
        [Bindable(false), Category("Behavior"), DefaultValue(""), TypeConverter(typeof(TextModeFieldTypeControlsConverter)), Description("要滚动的对象。")]
        public string TextMode  //要进行校验的表达式
        {
            get
            {
                return tb.TextMode.ToString();
            }
            set
            {
                if (value == "Password") tb.TextMode = TextBoxMode.Password;
                if (value == "MultiLine")
                {
                    tb.TextMode = TextBoxMode.MultiLine;
                    tb.Attributes.Add("onkeyup", "return isMaxLen(this)");
                }
                if (value == "SingleLine") tb.TextMode = TextBoxMode.SingleLine;
            }
        }

        [Bindable(false), Category("Behavior"), DefaultValue(""), TypeConverter(typeof(RequiredFieldTypeControlsConverter)), Description("要滚动的对象。")]
        public string RequiredFieldType  //要进行校验的表达式
        {
            get
            {
                object o = ViewState["RequiredFieldType"];
                return (o == null) ? "" : o.ToString();
            }
            set
            {
                ViewState["RequiredFieldType"] = value;
                SetValiateControls();
            }
        }



        [Bindable(false), Category("Behavior"), DefaultValue("可为空"), TypeConverter(typeof(CanBeNullControlsConverter)), Description("要滚动的对象。")]
        public string CanBeNull  //要表达式是否可以为空
        {
            get
            {
                object o = ViewState["CanBeNull"];
                return (o == null) ? "" : o.ToString();
            }
            set
            {
                ViewState["CanBeNull"] = value;
                SetValiateControls();
            }
        }


        //是否进行 ' 号替换
        [Bindable(true), Category("Appearance"), DefaultValue("")]
        public bool IsReplaceInvertedComma
        {
            get
            {
                object o = ViewState["IsReplaceInvertedComma"];
                if (o == null || o.ToString().Trim() == "")
                {
                    return true;
                }
                else
                {
                    return o.ToString().ToLower() == "true" ? true : false;
                }
            }
            set
            {
                ViewState["IsReplaceInvertedComma"] = value;
            }
        }



        [Bindable(true), Category("Appearance"), DefaultValue("")]
        public string ValidationExpression
        {
            get
            {
                object o = ViewState["ValidationExpression"];
                if (o == null || o.ToString().Trim() == "")
                {
                    return null;
                }
                else
                {
                    return o.ToString().ToLower();
                }
            }
            set
            {
                ViewState["ValidationExpression"] = value;
            }
        }

        [Bindable(true), Category("Appearance"), DefaultValue("")]
        public string Text
        {
            get
            {

                if (this.RequiredFieldType == "日期")
                {
                    try
                    {
                        return DateTime.Parse(tb.Text).ToString("yyyy-MM-dd");
                    }
                    catch
                    {
                        return "1900-1-1";
                    }
                }

                if (this.RequiredFieldType == "日期时间")
                {
                    try
                    {
                        return DateTime.Parse(tb.Text).ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    catch
                    {
                        return "1900-1-1 00:00:00";
                    }
                }
                else
                {
                    return IsReplaceInvertedComma ? tb.Text.Replace("'", "''").Trim() : tb.Text;
                }
            }
            set
            {
                if (this.RequiredFieldType.IndexOf("日期") >= 0)
                {
                    try
                    {
                        tb.Text = DateTime.Parse(value).ToString("yyyy-MM-dd");
                    }
                    catch
                    {
                        tb.Text = "";
                    }
                }

                if (this.RequiredFieldType.IndexOf("日期时间") >= 0)
                {
                    try
                    {
                        tb.Text = DateTime.Parse(value).ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    catch
                    {
                        tb.Text = "";
                    }
                }
                else
                {
                    tb.Text = value;
                }
            }

        }

        //调控件的高度属性
        [Bindable(false), Category("Appearance"), DefaultValue("")]
        override public Unit Height
        {
            get
            {
                return tb.Height;
            }
            set
            {
                tb.Height = value;
            }
        }
 1 
查看完整版本: 续:本论坛重写TextBox的功能