📄 textboxplus.cs
字号:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace Chapter_10_Controls
{
public enum TextTypes
{
CurrencyText,
DecimalText,
PlainText
}
/// <summary>
/// Summary description for TextBoxPlus.
/// </summary>
[DefaultProperty("LabelText"),
ToolboxData("<{0}:TextBoxPlus runat=server></{0}:TextBoxPlus>")]
public class TextBoxPlus : System.Web.UI.WebControls.TextBox
{
private string _labelText;
private TextTypes _textType = TextTypes.PlainText;
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string LabelText
{
get
{
return _labelText;
}
set
{
_labelText = value;
}
}
[Bindable(true),
Category("Appearance"),
DefaultValue(TextTypes.PlainText)]
public TextTypes TextType
{
get
{
return _textType;
}
set
{
_textType = value;
}
}
/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
output.Write(LabelText);
if ( Page.IsPostBack )
{
if ( _textType != TextTypes.PlainText )
{
this.FormatText();
}
}
base.Render(output);
}
protected void FormatText()
{
switch(_textType)
{
case TextTypes.CurrencyText:
this.Text=(double.Parse(this.Text)).ToString("C");
break;
case TextTypes.DecimalText:
this.Text=(Convert.ToInt32(this.Text)).ToString("F");
break;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -