I want to have a text control that only accepts numbers. (Just integer values like 45 or 366)
What is the best way to do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
IntCtrl,Masked Edit Control, andNumCtrlare all designed to do just this, with different levels of control. Checkout the wx demo under “More Windows/Controls” to see how they work.(Or, if you’re instead really looking forward to doing this directly with a raw TextCtrl, I think you’d want to catch EVT_CHAR events, test the characters, and call evt.Skip() if it was an allowed character.)