在OnKeyPress里面判断: try if strtoint(Edit1.Text)>=36 then Key := $0 except end
在form.show里 edit1.maxlength:=36;
在OnKeyPress里面判断: try if StrToInt(Edit1.Text) > 36 || StrToInt(Edit1.Text) < 1 then Key = nil except Key = nil; //不是数字 end
改一下 在OnKeyPress里面判断: try if StrToInt(Edit1.Text+Key) > 36 || StrToInt(Edit1.Text+Key) < 1 then Key = nil except Key = nil; //不是数字 end
在edit的ONchange事件中﹕ try if StrToInt(Edit1.Text) > 36 then edit1.text:='36'; except edit1.text:='0'; //不是数字 end
||是c里的,在delphi里也可以吗?
我明白你的意思了,像你这种情况只能是写一个继承TEdit的控件来实现你的需求了。 这很简单的。
Edit控件中的MaxLength属性,就可以指定最大输入数。
试了一下; 1.procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin try if length(Edit1.Text)>=5 then Key := #0; except ShowMessage('not'); end; end;2.procedure TForm1.FormCreate(Sender: TObject); begin Edit1.MaxLength := 5; end;各位都在上面说过了的....
在edit的ONKeyPress事件中﹕ if not (Key in['0'..'9',#8,#13]) then key=#0 else if StrToInt(Edit1.Text) > 36 then begin edit1.text:='36'; showmessage('输入最大值为36') end;
Key = nil
try
if strtoint(Edit1.Text)>=36 then Key := $0
except
end
edit1.maxlength:=36;
在OnKeyPress里面判断:
try
if StrToInt(Edit1.Text) > 36 || StrToInt(Edit1.Text) < 1 then
Key = nil
except
Key = nil; //不是数字
end
在OnKeyPress里面判断:
try
if StrToInt(Edit1.Text+Key) > 36 || StrToInt(Edit1.Text+Key) < 1 then
Key = nil
except
Key = nil; //不是数字
end
try
if StrToInt(Edit1.Text) > 36 then
edit1.text:='36';
except
edit1.text:='0'; //不是数字
end
这很简单的。
1.procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
try
if length(Edit1.Text)>=5 then
Key := #0;
except
ShowMessage('not');
end;
end;2.procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.MaxLength := 5;
end;各位都在上面说过了的....
if not (Key in['0'..'9',#8,#13]) then key=#0
else if StrToInt(Edit1.Text) > 36 then
begin
edit1.text:='36';
showmessage('输入最大值为36')
end;