Click to See Complete Forum and Search --> : general
kanchanapally
November 25th, 1999, 01:51 AM
i want only numbers to be entered in my text box and must not allow any thing to be entered into it.
how can i do it.
i am not getting with like operator in keydown event.
please help me
-srikanth
Lothar Haensler
November 25th, 1999, 01:59 AM
There is only ONE truly reliable solution to this that I know of:
use the SetWindowLong API and set the GWL_STYLE to ES_NUMBER.
Other approaches (trapping keyup, keypress and so on), although widely used, do not work in all cases, because the usually fail to trap Paste operations via Ctrl+V and Shift+Ins or the context menu.
Ravi Kiran
November 25th, 1999, 05:18 AM
Hi Lothar,
ES_NUMBER for GWL_STYLE of a Text box is defined only for WINVER > 0x400. DOes that mean it works on 95? I dont think so. It sure works on WIn nt 4.0 SP3 through. I tried.
As an aside:
Whay is that this code doesn't work for setting the text box read only??
lStyle = GetWindowLong(txtboxHwnd, GWL_STYLE)
lStyle = lStyle Or ES_READONLY
' lrtn = SetWindowLong(txtboxHwnd, GWL_STYLE, lStyle) ' DOESnt work
lrtn = SendMessageLong(txtboxHwnd, EM_SETREADONLY, 1, 0) ' Only works??
Any ideas?
RK
Lothar Haensler
November 25th, 1999, 07:33 AM
some styles are only interpreted when the control is created. ES_READONLY is one of them.
from the docs:
"To change this style after the control has been created, use the EM_SETREADONLY message"
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.