I have some radio buttons that decide the type of input to be given to the CEdit
control. By design, my CEdit control accepts numbers and characters.
Is there a way to limit this input to only numbers only when the user clicks on a provided radio button? Also, when the user clicks on the other option (i.e. alpha-numeric mode), is it possible to switch back?
I set up my CEdit
control to accept alpha-numeric characters using Visual C++'s GUI (i.e. right click on the control -> Properties -> "Styles" tab -> select "Number").
An example use case:
CEdit
control in consideration shows.At this point I want to restrict input to the CEdit
control to only numbers. Similarly, after this, if the user clicks on the alpha-numeric radio button again, I want to remove that restriction.
Yes, use CEdit::ModifyStyle()
to either set or clear the ES_NUMBER style.
So, to make it accept numbers only:
CEdit *pEdit = // get your control here ...
pEdit->ModifyStyle(0, ES_NUMBER);
And to revert to accepting all characters:
pEdit->ModifyStyle(ES_NUMBER, 0);