On the Rise of the last time, I made a control to input the amount of creden like Kingdee. Today I actually used the control to modify several operations and enhance some features.
The main changes are as follows:
1. When the amount is modified, the integer can automatically jump to the decimal point (after the red line) and re-write the decimal point when "." Is input.
2. modified the decimals to input other non-numeric elements.
Code As follows:
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> " )
]
// Set default properties
Public Class Voucherinput: webcontrol
{
Private Textbox _ textbox; // Integer
Private Textbox _ ptextbox; // Decimal places
Attribute # Region Attribute
[
Bindable ( True ),
Category ( " Appearance " ),
Defaultvalue ( "" ),
Description ( " Amount " )
]
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
Method # Region Method
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> " ); // Character Control
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
}
}
conclusion: the old problem still persists. When the Delete amount is deleted, the decimal point and the entire number are deleted separately, the main reason is that I cannot use the cursor to determine whether to turn to an integer.