在Inno Setup中的文本框中需要一个数字 [英] Required a number in text box in Inno Setup

查看:70
本文介绍了在Inno Setup中的文本框中需要一个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里找到了所需的代码.只允许在文本框中输入数字.但是我仍然想要更多,如果不在此文本框中输入数字,该按钮将不提供下一步"按钮.

I found a code here that I needed. To only allow write numbers in a text box. But I still wanted more, which does not offer up the "Next" button without write the number in this text box.

能帮帮我吗?

procedure NumbersOnly(Sender: TObject; var Key: Char);
var
  S: string;
begin
  S := ('1234567890'#8);
  if Pos(Key, S) = 0 then 
    Key := #0;
end;

推荐答案

您可以在

You can setup the next button to be enabled or disabled in the CurPageChanged event when the user reaches the page where resides your edit box. Except that you need to monitor changes of that edit box to enable or disable the next button according to whether there's something entered in that edit box. For this you need to write a handler for the OnChange event. Here is an example:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Code]
var
  MyEdit: TNewEdit;
  MyPage: TWizardPage;

procedure MyEditChange(Sender: TObject);
begin
  { enable the next button if the edit box is not empty; disable otherwise }
  WizardForm.NextButton.Enabled := MyEdit.Text <> '';
end;

procedure MyEditKeyPress(Sender: TObject; var Key: Char);
var
  KeyCode: Integer;
begin
  { allow only numbers }
  KeyCode := Ord(Key);
  if not ((KeyCode = 8) or ((KeyCode >= 48) and (KeyCode <= 57))) then
    Key := #0;
end;

procedure InitializeWizard;
begin
  MyPage := CreateCustomPage(wpWelcome, 'Caption', 'Description');

  MyEdit := TNewEdit.Create(WizardForm);
  MyEdit.Parent := MyPage.Surface;
  MyEdit.Left := 0;
  MyEdit.Top := 0;
  MyEdit.Width := 150;
  MyEdit.OnChange := @MyEditChange;
  MyEdit.OnKeyPress := @MyEditKeyPress;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  { if the currently turned wizard page is the one with the edit box, enable }
  { the next button if the edit box is not empty; disable otherwise }
  if CurPageID = MyPage.ID then
    WizardForm.NextButton.Enabled := MyEdit.Text <> '';
end;

这篇关于在Inno Setup中的文本框中需要一个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆