Главная страница | назад





Article #17453: Range checking in an edit

 Question and Answer Database
FAQ2453C.txt Range checking in an edit
Category :VCL
Platform :All
Product :C++Builder 3.x
Question:
I have to let a user type numbers in a edit control from 0 to 255 and no
caracters. How can i capture the keys the user presses and if they are not
valid or would make the number greater then 255 just ignore the key that was
pressed.
Answer:
In the OnKeyPress event of the Edit component:
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
if ((Key < '0' || Key> '9') && Key != 8) Ke y= 0;
}
7/2/98 10:32:32 AM

Last Modified: 01-SEP-99