简陋的会计凭证金额输入控件(加强)
2006-10-27 14:48
316 查看
上次一时兴起,做了一个仿金蝶的凭证金额输入的控件,今天使用了下,真的奇陋无比,所以花了几个小时加强了点功能
主要有增加以下功能
1、实现整数和小数位的分开
2、在得到焦点的时候能控制在整数位
3、在输入“.”的时候可以自动跳转到小数位(红线后)
4、能设置和获得原始的数据
以下是示意图
代码如下
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(Images/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(Images/textPoint.gif)");
_PTextBox.Style.Add(HtmlTextWriterStyle.BorderWidth, "0");
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>"); //对字符的控制
}
#endregion Overriden methods
}
}
总结
现在还是不满意,比如删数据的时候还是小数位和整数位分开发删除,目前还没有具体的想法
主要有增加以下功能
1、实现整数和小数位的分开
2、在得到焦点的时候能控制在整数位
3、在输入“.”的时候可以自动跳转到小数位(红线后)
4、能设置和获得原始的数据
以下是示意图
代码如下
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(Images/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(Images/textPoint.gif)");
_PTextBox.Style.Add(HtmlTextWriterStyle.BorderWidth, "0");
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>"); //对字符的控制
}
#endregion Overriden methods
}
}
总结
现在还是不满意,比如删数据的时候还是小数位和整数位分开发删除,目前还没有具体的想法
相关文章推荐
- 简陋的会计凭证金额输入控件(再加强) [转]
- 简陋的会计凭证金额输入控件(再加强)
- 简陋的会计凭证金额输入控件(加强) [转]
- 简陋的会计凭证金额输入控件(再加强)
- 简陋的会计凭证金额输入控件(加强)
- 简陋的会计凭证金额输入控件(再加强)[转]
- 简陋的会计凭证金额输入控件
- 简陋的会计凭证金额输入控件
- 简陋的会计凭证金额输入控件 [转]
- 中国式会计凭证货币金额控件(FarPoint Spread Custom CellType版)
- 中国式会计凭证货币金额控件(.NET版)
- 【WPF】自定义金额输入控件CurrencyEditor和限制输入控件FieldTextBox
- 对会计软件中凭证输入模块的一点看法
- 对会计中凭证输入模块的一点看法
- Android金额输入控件
- 对会计软件中凭证输入模块的一点看法
- SMARTFORM的使用BSIS会计凭证中的字段DMBTR(本币金额)报错
- 收取金额查询—日历控件&查询两个日期之间的数据
- 用jQuery.form实现批量输入控件的提交
- 输入手机号码 和 金额有效性的判断