简陋的会计凭证金额输入控件 [转]

今天看到金碟的会计凭证,看到了它很人性化的金额输入框,突然兴起也想玩个,就做了这么简陋的一个. 不过这也是我第一个自定义控件,以后慢慢的完善它,达到有用的程度 其实很简单.先把代码贴出来,再介绍代码的说明

using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Voucher
{
    [DefaultProperty("jText")]
    [ToolboxData(@"<{0}:VoucherInput jText = '000'  
    runat='server'></{0}:VoucherInput>")
    ]
    public class VoucherInput : WebControl, INamingContainer
    {
      
        private TextBox _TextBox;

        #region 属性
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(""),
        Description("金额")
        ]
        public string jText
        {
            get
            {
                EnsureChildControls();
                return _TextBox.Text;
            }
            set
            {
                EnsureChildControls();
                _TextBox.Text = value;
            }
        }

        #endregion Properties delegated to child controls

        #region 方法
        protected override void CreateChildControls()
        {
            Controls.Clear();
            _TextBox = new TextBox();
            _TextBox.ID = "TextBox1";
            _TextBox.MaxLength = 15;
            _TextBox.Width = 120;
            _TextBox.Height = 20;
            _TextBox.Attributes.Add("onkeypress", "keyPress()");
            _TextBox.Style.Add(HtmlTextWriterStyle.BackgroundImage, "url(Images/text.gif)");
            _TextBox.Style.Add(HtmlTextWriterStyle.Direction, "rtl");
            _TextBox.Style.Add(HtmlTextWriterStyle.BorderWidth, "0");

            this.Controls.Add(_TextBox);

        }

        protected override void Render(HtmlTextWriter writer)
        {
            AddAttributesToRender(writer);
            _TextBox.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;}}</script>");
        }
        #endregion Overriden methods

    }
}

 

一、添加引用       using System.Web.UI;        using System.Web.UI.WebControls; 二、设置默认的属性和默认的标志       [DefaultProperty("jText")]       [ToolboxData(@"<{0}:VoucherInput jText = '0.00' runat='server'>") ]       他们在asp.net的设计页面上就等于<cc1:VoucherInput ID="VoucherInput1" runat="server" jText="0.00" /> 三、设置TextBox的属性       背景图片、最大字符等等 四、输出javascrip脚本,控制文本框只能输入数字和小数点 五、界面如下 总结 这个还是有很大的问题,还远远打不到金碟的水平,不过这个也是我第一个自定义控件,我会不断的升级,如果真的能和金蝶做的一样,会马上发布的。

转载于:https://www.cnblogs.com/ddlzq/p/3529462.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值