TEXTBOX that can only be operated

xiaoxiao2021-03-06  73

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 should not be; 5: just get a string, but also improve your 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 {///

/// NumTextbox's summary description. /// public class textBoxNumex: system.windows.Forms.TextBox {public const INT WM_CONTEXTMENU = 0x007b; // Right-click menu message public const INT WM_CHAR = 0x0102; // Enter a character message (keyboard input, input method Input doesn't seem to be this message) Public const INT WM_CUT = 0x0300; // Program Send this message to an edit box or ComboBox to delete the currently selected text public const amount wm_copy = 0x0301; // Send this message to an edit box or ComboBox Copy the currently selected text to the clipboard public const INT WM_PASTE = 0x0302; / / Program Send this message to get the data PUBLIC Const Int WM_CLEAR = 0x0303 in the clipboard from the clipboard; // Program Send this message to EditControl or ComboBox Clear the currently selected content; public const INT WM_UNDO = 0x0304; // Send this message to editcontrol or ComboBox to undo the last operation

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

转载请注明原文地址:https://www.9cbs.com/read-92639.html

New Post(0)