Question

I have 2 questions...my 1st question is how do I limit the number of character typed in a textbox in MFC..say if I want the user to type only 4 characters..the text box should take only 4 character.And my 2nd question is when it exceeds the character limit it should jump to the next textbox/tab control.I tried using the following code..but it seem to not work in my case...Please help me if you know any alternatives...

CEdit::SetLimitText(4);

Was it helpful?

Solution

handle the EN_CHANGE message (OnEnChange). In that handler, find the number of chars the textbox has. If it's more than 4, remove the last ones. If it's four, use NextDlgCtrl() to tab to the next control or use SetFocus() to set the focus to a specific control.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top