码迷,mamicode.com
首页 > 其他好文 > 详细

简陋的会计凭证金额输入控件(再加强)[转]

时间:2015-06-30 17:49:26      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:

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

    }
}

 

简陋的会计凭证金额输入控件(再加强)[转]

标签:

原文地址:http://www.cnblogs.com/ddlzq/p/4611038.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!