簡陋的會計憑證金額輸入控制項(再加強)[轉]

來源:互聯網
上載者:User

標籤:

using System;using System.ComponentModel;using System.Web.UI;using System.Web.UI.WebControls;namespace Voucher{    [DefaultProperty("jText")]    [ToolboxData(@"<{0}:VoucherInput jText = ‘‘      runat=‘server‘></{0}:VoucherInput>")    ]    //設定預設的屬性    public class VoucherInput : WebControl    {              private TextBox _TextBox;    //整數位        private TextBox _PTextBox;   //小數位        #region 屬性        [        Bindable(true),        Category("Appearance"),        DefaultValue(""),        Description("金額")        ]        public string jText        {            get            {                EnsureChildControls();                return _TextBox.Text + "." + _PTextBox.Text;            }            set            {                EnsureChildControls();                if (value == "" || value == null)                {                                   }                else                {                    string[] Allstring = value.Split(‘.‘);                    _TextBox.Text = Allstring[0];                    _PTextBox.Text = Allstring[1];                 }            }        }        #endregion Properties delegated to child controls        #region 方法        protected override void CreateChildControls()        {            Controls.Clear();            _TextBox = new TextBox();            _TextBox.ID = "TextBox1";            _TextBox.MaxLength = 13;            _TextBox.Width = 120;            _TextBox.Height = 20;            _TextBox.Attributes.Add("onkeypress", "keyPress()");                        _TextBox.Style.Add(HtmlTextWriterStyle.BackgroundImage, "url(text.gif)");            _TextBox.Style.Add(HtmlTextWriterStyle.Direction, "rtl");            _TextBox.Style.Add(HtmlTextWriterStyle.BorderWidth, "0");                        _PTextBox = new TextBox();            _PTextBox.Width = 15;            _PTextBox.Height = 20;            _PTextBox.MaxLength = 2;            _PTextBox.ID = "PTextBox";            _PTextBox.Style.Add(HtmlTextWriterStyle.BackgroundImage, "url(textPoint.gif)");            _PTextBox.Style.Add(HtmlTextWriterStyle.BorderWidth, "0");            _PTextBox.Attributes.Add("onFocus", "PFocus()");            _PTextBox.Attributes.Add("onkeypress", "PkeyPress()");            this.Controls.Add(_TextBox);            this.Controls.Add(_PTextBox);        }        protected override void Render(HtmlTextWriter writer)        {            AddAttributesToRender(writer);            _TextBox.RenderControl(writer);            _PTextBox.RenderControl(writer);            writer.Write("<script language=javascript>function keyPress(){if(!(event.keyCode>=48&&event.keyCode<=57 ||event.keyCode==46 || event.keyCode==45)){event.keyCode = 0;}if(event.keyCode==46){event.keyCode = 0;document.getElementById(‘PTextBox‘).focus();}}</script>");   //對字元的控制            writer.Write("<script language=javascript>function PFocus(){ var box=document.getElementById(‘PTextBox‘); var rng = box.createTextRange(); rng.collapse(true); rng.moveEnd(‘character‘,2); rng.moveStart(‘character‘,0); rng.select(); }</script>");            writer.Write("<script language=javascript>function PkeyPress(){if(event.keyCode==46){event.keyCode = 0;} if(!(event.keyCode>=48&&event.keyCode<=57 ||event.keyCode==46 || event.keyCode==45)){event.keyCode = 0;} }</script>");        }        #endregion Overriden methods    }}

 

簡陋的會計憑證金額輸入控制項(再加強)[轉]

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.