BCB :: Number response in Edit

xiaoxiao2021-03-06  69

I remember there is a code can be

// Get the current type flag long dwstyle = getWindowlong (edit1-> handle, gwl_style); // Add ES_NUMBER Type SetWindowlong (Edit1-> Handle, GWL_Style, DWStyle | ES_NUMBER);

You try this code, if you pay, ok?

If the building is just a number of 0 to 9, then the way upstairs is indeed simple and feasible.

If you allow Edit to enter scientific counts? (For example, 3e1, this is also a standard value) also has a negative number or decimal (for example: -1, 1.2), etc.

I am afraid that the code above is not ideal. I have repeatedly debugged, the following code can meet this request: only allows Edit1 to enter any valid value. Try it. In order to make the interface more complete, I use a global variable NPOS to remember the cursor position of Edit, of course, if you want to be simple, you can go.

/ / -------------------------------------------------------------------------------------------- --------------------------- String STEMP = ""; // global variable, memory edit original digital int NPOS = 0; // Global variable, memory EDIT cursor location // ------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------- void __fastcall tform1 :: edit1change (TOBJECT * Sender) {Try {String s = edit1-> text; if (! sisempty ()) s.todouble (); STEMP = S;} catch (...) {showMessage ("Lifening me! Not a number."); edit1-> Text = step; edit1-> selstart = npos;}} // --------------------------------- ---------------------------------------- void __fastcall tform1 :: edit1keyup (TOBJECT * SENDER , Word & Key, TshiftState Shift) {npos = Edit1-> Selstart;} // ---------------------------------------------------------------------------------------------------------------------------- ------------------------------------------- void __fastcall tform1 :: edit1mouseup TOBJECT * SENDER, TMOUSEBUTTON button, TshiftState Shift, Int x, int y) {npos = edit1-> selstart;} // ----------------------- -------------------------------------------------- -

///

A simple practice

ANSISTRING INPUTKEY = KEY; ANSISUSTRING VALIDKEY = ANSISUSTRING ("0123456789.ccvv"); // Let you want to enter visible characters ansistring controlkey = Ansistring ("ccvv"); //> Control character here

// If the button is back space or Tab does not judge if ((key! = Vk_back) | // Here, the determination of the invisible character {// Judge whether the input character is in ValidKey, Not, set the input to empty IF (validkey.pos (inputkey) == 0) {key = 0;} else if (validkey.pos (inputkey)! = 0) {// This views the CTRL button is pressed, If it is not considered invalid, use WinAPI to get IF ((getKeyState (VK_RControl) && 0x80) == 0) {// Ctrl is not pressed, invalid This input key = 0;} // is here, the hotkey input , Will automatically register with the hotkey registered accordingly, no control}}

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

New Post(0)