using System;
using System.ComponentModel;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace XControl
{
/// <summary>¸¡µãÊýÊäÈë¿Ø¼þ¡£Ö»ÄÜÊäÈëÊý×Ö£¬²¢¿ÉÒԹ涨·¶Î§¡¢¼ä¸ô¡£</summary>
[Description("¸¡µãÊýÊäÈë¿Ø¼þ")]
[ToolboxData("<{0}:RealBox runat=server></{0}:RealBox>")]
[ToolboxBitmap(typeof(TextBox))]
[ControlValueProperty("Value")]
public class RealBox : TextBox
{
/// <summary>³õʼ»¯Êý×ÖÊäÈë¿Ø¼þµÄÑùʽ¡£</summary>
public RealBox()
: base()
{
this.ToolTip = "Ö»ÄÜÊäÈ븡µãÊý£¡";
BorderWidth = Unit.Pixel(0);
BorderColor = Color.Black;
BorderStyle = BorderStyle.Solid;
Font.Size = FontUnit.Point(10);
Width = Unit.Pixel(70);
if (String.IsNullOrEmpty(Attributes["style"])) this.Attributes.Add("style", "border-bottom-width:1px;text-align : right ");
}
/// <summary>ÒÑÖØÔØ¡£</summary>
/// <param name="e"></param>
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
// УÑé½Å±¾
Helper.HTMLPropertyEscape(this, "onkeypress", "return ValidReal({0});", AllowMinus ? 1 : 0);
Helper.HTMLPropertyEscape(this, "onblur", "return ValidReal2();");
Helper.HTMLPropertyEscape(this, "onkeyup", "FilterNumber(this,{0});", Helper.JsObjectString(
// "allowFloat", 1, // ĬÈÏÊÇtrue
"allowMinus", AllowMinus ? 1 : 0
));
this.Page.ClientScript.RegisterClientScriptResource(typeof(NumberBox), "XControl.TextBox.Validator.js");
//Èç¹ûûÓÐÖµ£¬ÔòĬÈÏÏÔʾ0
if (String.IsNullOrEmpty(Text)) Text = "0";
}
/// <summary>µ±Ç°Öµ</summary>
[Category(" רÓÃÊôÐÔ"), DefaultValue(0), Description("µ±Ç°Öµ")]
public Double Value
{
get
{
if (String.IsNullOrEmpty(Text)) return 0;
Double k = 0;
if (!Double.TryParse(Text, out k)) return 0;
return k;
}
set
{
Text = value.ToString();
}
}
/// <summary>ÊÇ·ñÔÊÐí¸ºÊý</summary>
[Category(" רÓÃÊôÐÔ"), DefaultValue(true), Description("ÊÇ·ñÔÊÐí¸ºÊý,ĬÈÏtrue")]
public bool AllowMinus
{
get
{
object o = ViewState["AllowMinus"];
if (o == null) o = true;
bool r;
if (bool.TryParse(o.ToString(), out r)) return r;
return true;
}
set
{
ViewState["AllowMinus"] = value;
}
}
}
}
|