Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
In my VC++ project, I want an Edit control that it ignores write anything except integer numbers and Dot(.) for giving float numbers.

I write a MyEdit class deived CEdit, in OnKeyDown() event :
UINT asciiCode = MapVirtualKey(nChar, 2);
	if( (asciiCode >= 48 && asciiCode <= 57) || asciiCode == 46)
		CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
	else 
		nChar = 0;



But the Edit Box gives any characters!
How do i ignore other characters?
Posted

1 solution

What you can do is to implement a class extension of CEdit. Inside the OnChar or OnKeyUp event you can get the text of your control, check for conformity an correct if necessary.
 
Share this answer
 
Comments
Zon-cpp 6-Jul-15 5:19am    
In OnKeyUp event, what do I do when the text of control is a character else 'numbers' and 'dot'?
Marc Hausmann 6-Jul-15 5:41am    
The on key up should give you the char value of the pressed key. In case of a character just return, in case of a digit add it to the control text, if a dot, check how many dots you have in the string and add it only if there are none.
barneyman 8-Jul-15 6:32am    
dont forget to handle paste, and selection edits

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900