我对 C++ Builder XE8 很陌生。
我希望必须输入的数字的最小和最大长度为六个数字,我还需要确保只输入数字(0 是例外),而不是字母字符、退格符、标点符号等。
如果输入的不是数字,我还想生成一个错误框。
我尝试了一些代码组合,其中三个可以在下面看到,但这些代码都不起作用。
任何帮助都将不胜感激!
(1)。
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, System::WideChar &Key)
{
Edit1->MaxLength = 6;
if (!((int)Key == 1-9)) {
ShowMessage("Please enter numerals only");
Key = 0;
}
}
(2)。
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, System::WideChar &Key)
{
Edit1->MaxLength = 6;
if (Key <1 && Key >9) {
ShowMessage("Please enter numerals only");
Key = 0;
}
}
(3)。
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, System::WideChar &Key)
{
Edit1->MaxLength = 6;
if( Key == VK_BACK )
return;
if( (Key >= 1) && (Key <= 9) )
{
if(Edit1->Text.Pos(1-9) != 1 )
ShowMessage("Please enter numerals only");
Key = 1;
return;
}
}