views:

215

answers:

1

hello all, 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);

+2  A: 

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.

Stefan
tnax for ur quick reply stefan...thats a good idea..actually I tried that but it didnt work somehow..but let me double check that again one more time and I also went through another article and thought of using ON_EN_MAXTTEXT..will try that real quick and will let u Know friend..
kiddo
Oh!stevan..I tried that now its working gr8..its simple but sumtime we tend to make things complicated..but anyways..I really appreciate ur help.
kiddo