When the user enters only the digital characters, the default textbox is unqualified. There are many netizens on the Internet to provide a lot of practices. I summed up a few points written in C #. : 1: You can only enter a character like this: -123456.789; 1234.789; 2: There is no two points in the input string: 12456.78 // correct; 12.456.78 // incorrect; 3: If the negative number can be Add a minus "-" in the top of the string, you can only add a character of the younger brother; 4: You can use the copy point function and menu function, but only the string that can correctly format, such as: 12.34 Yes, ABC is not available; 5: Just get a string, but also improve its own needs on this basis, such as adding support for hexadecimal. The code is written under .NET under the .NET; use system; using system.windows.forms;
Namespace NumTextBox {///
Public textBoxNumex () {// // Todo: Add Constructor Logic //} Protected Override Void WndProc (Ref Message M) {Switch (M.MSG) {CASE WM_CHAR: System.Console.writeline (M.WParam ); BOOL ISSIGN = ((int) m.wparam == 45); BOOL ISNUM = ((int) m.wpaam> = 48) && ((int) m.wparam <= 57); bool isback = (int) M.WParam == (int) keys.back; bool isdelete = (int) m.wParam == (int) keys.delete; // actually this is a "." button BOOL ISCTR = (INT) m. WPARAM == 24) || ((int) m.wparam == 22) || (int) m.wparam == 26) || (int) m.wparam == 3); if (isnum || ISBACK || IscTr) {base.wndProc (Ref m);} if (iv) {if (this.SelectionStart! = 0) {Break;} Base.WndProc (ref M); Break;}}}}}}}}}} (THISTEXT.INDEXOF (".") <0) {base.WndProc (Ref m);}}} f ((int) m.wparam == 1) {this.selectall ();} Break; Case WM_PASTE: IDataObject idata = clipboard.getdataObject (); // Take a shear panel object if (Idata .GetdataPresent (dataFormats.text) // Decision is a text {string str = (string) idata.getdata (data); // Take Data IF (MatchNumber (STR)) {Base.WndProc (REF M); Break;}} m.Result = (intptr) 0; // No Break; default: base.wndProc (Ref M); Break;}} private bool matchnumber (string clipboardtext) {int index = 0; string strnum = "-0.123456789";
Index = clipboardtext.indexof (Strnum [0]); if (index> = 0) {if (index> 0) {Return false;} index = this.selectionstart; if (index> 0) {Return False;}} index = ClipBoardText.indexof (Strnum [2]); IF (INDEX! = - 1) {index = this.text.indexof (Strnum [2]); if (INDEX! = - 1) {Return False;}}}
For (int i = 0; i - From (http://blog.9cbs.net/hbxtlhx/archive/2004/11/12/178510.aspx)