闪客动漫天地
欢迎 游客 , 注册 | 登录 | 会员 | 界面 | 简洁版本 | 在线 | 帮助
闪客动漫天地论坛

发表新主题 回复该主题
本主题被查看946次, 共1个帖子, 1页, 当前为第1页     选择页数: 1      跳转到第   上一主题   下一主题
标题: 再续:本论坛重写Textbox的功能
注册会员
UID: 309683
来自:
精华: 0
积分: 54
帖子: 54
注册: 2007-6-18 15:03:00
状态: 离线
威望: 0.00
金钱: 12.00 元
只看楼主 2007-06-19 11:02
再续:本论坛重写Textbox的功能
//调控件的宽度属性
        [Bindable(true), Category("Appearance"), DefaultValue("")]
        override public Unit Width
        {
            get
            {
                return tb.Width;
            }
            set
            {
                tb.Width = value;
            }
        }

        private int _rows = 5;
        //调控件的宽度属性
        [Bindable(true), Category("Appearance"), DefaultValue(1)]
        public int Rows
        {
            get
            {
                return _rows;
            }
            set
            {
                _rows = value;
            }
        }

        private int _cols = 45;
        //调控件的宽度属性
        [Bindable(true), Category("Appearance"), DefaultValue(30)]
        public int Cols
        {
            get
            {
                return _cols;
            }
            set
            {
                _cols = value;
            }
        }


        private int _size = 45;
        //调控件的宽度属性
        [Bindable(true), Category("Appearance"), DefaultValue(30)]
        public int Size
        {
            get
            {
                return _size;
            }
            set
            {
                _size = value;
            }
        }


        //调控件的宽度属性
        [Bindable(true), Category("Appearance"), DefaultValue(true)]
        public override bool Enabled
        {
            get
            {
                return tb.Enabled;
            }
            set
            {
                tb.Enabled = value;
            }
        }


        private string _maximumValue = null;

        [Bindable(true), Category("Appearance"), DefaultValue(null)]
        public string MaximumValue
        {
            get
            {
                return _maximumValue;
            }
            set
            {
                _maximumValue = value;
            }
        }

        private string _minimumValue = null;
        [Bindable(true), Category("Appearance"), DefaultValue(null)]
        public string MinimumValue
        {
            get
            {
                return _minimumValue;
            }
            set
            {
                _minimumValue = value;
            }
        }




        /// <summary>
        /// 将此控件呈现给指定的输出参数。
        /// </summary>
        /// <param name="output"> 要写出到的 HTML 编写器 </param>
        protected override void Render(HtmlTextWriter output)
        {
            //output.Write(Text);
            if (this.TextMode == "MultiLine")
            {
                output.WriteLine("<script type=\"text/javascript\">");
                output.WriteLine("function isMaxLen(o){");
                output.WriteLine("var nMaxLen=o.getAttribute? parseInt(o.getAttribute(\"maxlength\")):\"\";");
                output.WriteLine(" if(o.getAttribute && o.value.length>nMaxLen){");
                output.WriteLine(" o.value=o.value.substring(0,nMaxLen)");
                output.WriteLine("}}</script>");

                this.AddAttributes("rows", Rows.ToString());
                this.AddAttributes("cols", Cols.ToString());
            }
            else
            {
                if (this.Width.Value.ToString() != "")
                {
                    if (Width.Type.ToString() != "")
                    {
                        this.AddAttributes("SIZE", (Width.Value / 10).ToString() + (Width.Type.ToString() == "ixel" ? "px" : "%"));
                    }

                    else
                    {
                        this.AddAttributes("SIZE", (Width.Value / 10).ToString() + "px");
                    }
                }

                if (this.Size.ToString() != "")
                {
                    this.AddAttributes("SIZE", this.Size.ToString());
                }
            }

            //当指定了输入框的最小或最大值时,则加入校验范围项
            if (this.MaximumValue != null || this.MinimumValue != null)
            {
                rangevalidator.ControlToValidate = tb.ID;
                rangevalidator.Type = ValidationDataType.Double;
                rangevalidator.ForeColor = System.Drawing.Color.Black;

                if (this.MaximumValue != null && this.MinimumValue != null)
                {
                    rangevalidator.MaximumValue = this.MaximumValue;
                    rangevalidator.MinimumValue = this.MinimumValue;
                    rangevalidator.ErrorMessage = " 当前输入数据应在" + this.MinimumValue + "和" + this.MaximumValue + "之间!";
                }
                else
                {
                    if (this.MaximumValue != null)
                    {
                        rangevalidator.MaximumValue = this.MaximumValue;
                        rangevalidator.ErrorMessage = " 当前输入数据允许最大值为" + this.MaximumValue;
                    }
                    if (this.MinimumValue != null)
                    {
                        rangevalidator.MinimumValue = this.MinimumValue;
                        rangevalidator.ErrorMessage = " 当前输入数据允许最小值为" + this.MinimumValue;
                    }
                }
                rangevalidator.Display = ValidatorDisplay.Static;
                this.Controls.Add(rangevalidator);
            }


            RenderChildren(output);
        }


        #region IPostBackDataHandler 成员



        public void RaisePostDataChangedEvent()
        { }


        public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            string presentValue = this.tb.Text;
            string postedValue = postCollection[postDataKey];

            if (!presentValue.Equals(postedValue))//如果回发数据不等于原有数据
            {
                this.Text = postedValue;
                this.tb.Text = postedValue;
                return true;
            }
            return false;

        }
        #endregion

    }

    public class RequiredFieldTypeControlsConverter : StringConverter
    {
        public RequiredFieldTypeControlsConverter() { }

        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }
        public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            ArrayList controlsArray = new ArrayList();
            controlsArray.Add("暂无校验");
            controlsArray.Add("数据校验");
            controlsArray.Add("电子邮箱");
            controlsArray.Add("移动手机");
            controlsArray.Add("家用电话");
            controlsArray.Add("身份证号码");
            controlsArray.Add("网页地址");
            controlsArray.Add("日期");
            controlsArray.Add("日期时间");
            controlsArray.Add("金额");
            controlsArray.Add("IP地址");
            controlsArray.Add("IP地址带端口");
            return new StandardValuesCollection(controlsArray);

        }
        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return false;
        }
    }


    public class CanBeNullControlsConverter : StringConverter
    {
        public CanBeNullControlsConverter() { }

        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            ArrayList controlsArray = new ArrayList();
            controlsArray.Add("可为空");
            controlsArray.Add("必填");

            return new StandardValuesCollection(controlsArray);

        }

        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return false;
        }
    }


    public class FormControlsConverter : StringConverter
    {
        public FormControlsConverter()
        {
        }

        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            ControlCollection Controls = ((Page)context.Container.Components[0]).Controls;
            ArrayList controlsArray = new ArrayList();
            for (int i = 0; i < Controls.Count; i++)
            {
                if ((Controls[i] is HtmlTable
                    || Controls[i] is HtmlForm
                    || Controls[i] is HtmlGenericControl
                    || Controls[i] is HtmlImage
                    || Controls[i] is Label
                    || Controls[i] is DataGrid
                    || Controls[i] is DataList
                    || Controls[i] is Table
                    || Controls[i] is Repeater
                    || Controls[i] is Image
                    || Controls[i] is Panel
                    || Controls[i] is PlaceHolder
                    || Controls[i] is Calendar
                    || Controls[i] is AdRotator
                    || Controls[i] is Xml
                    ))
                {
                    controlsArray.Add(Controls[i].ClientID);
                }
            }
            return new StandardValuesCollection(controlsArray);

        }

        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return false;
        }
    }
#1  
发表新主题 回复该主题
本主题被查看946次, 共1个帖子, 1页, 当前为第1页     选择页数: 1      跳转到第







现在的时间是 2008-07-21 08:16:21
沪ICP备05003105号

版权所有 闪客俱乐部  
         Powered by Discuz!NT 1.0.6666    Copyright © 2001-2008 Comsenz Inc.
Processed in 0.16 seconds