如何限制 NSIS 中的文本框字符数

How to limit the number of text box characters in NSIS

我想将每个文本框中的字符数限制为 4 位数字。

在C#Winform中可以实现,但不熟悉在NSIS中如何使用

尝试的操作:

我放了标签,我正在引导输入到四位数。

但这并不好。

我试图通过 NSIS 论坛查找信息,但找不到。

附上文本框图片:

text box

NSIS代码:

Function Test
  !insertmacro MUI_INSTALLOPTIONS_READ [=10=] "pageInputLicenseInfo.ini" "Settings" "State"
  ${If} [=10=] == 9 # btton 
    !insertmacro MUI_INSTALLOPTIONS_READ $R0 "pageInputLicenseInfo.ini" "Field 1" "State"
    !insertmacro MUI_INSTALLOPTIONS_READ $R1 "pageInputLicenseInfo.ini" "Field 2" "State"
    !insertmacro MUI_INSTALLOPTIONS_READ $R2 "pageInputLicenseInfo.ini" "Field 3" "State"
    !insertmacro MUI_INSTALLOPTIONS_READ $R3 "pageInputLicenseInfo.ini" "Field 4" "State"
    !insertmacro MUI_INSTALLOPTIONS_READ $R4 "pageInputLicenseInfo.ini" "Field 5" "State"
    !insertmacro MUI_INSTALLOPTIONS_READ $R5 "pageInputLicenseInfo.ini" "Field 6" "State"

    nsExec::ExecToStack '$INSTDIR\ParamterTestConsole.exe ${PRODUCT_NAME} $R0 $R1$R2$R3$R4$R5'

    Pop  ; Exit code
    Pop  ; console OUTPUT

    Blah blah..........

FunctionEnd

NSIS INI 文件:

; Ini file generated by the HM NIS Edit IO designer.
[Settings]
NumFields=14
Title=test

[Field 1]
Type=Text
Text=1
Left=29
Right=275
Top=46
Bottom=57

[Field 2]
Type=Text
Text=123
Left=30
Right=60
Top=67
Bottom=78

[Field 3]
Type=Text
Text=123
Left=74
Right=103
Top=67
Bottom=78

[Field 4]
Type=Text
Text=123
Left=121
Right=149
Top=67
Bottom=78

[Field 5]
Type=Text
Text=123
Left=164
Right=193
Top=67
Bottom=78

[Field 6]
Type=Text
Text=123
Left=206
Right=236
Top=67
Bottom=78

[Field 7]
Type=Label
Text=IP
Left=1
Right=15
Top=48
Bottom=56

[Field 8]
Type=Label
Text=Key
Left=1
Right=20
Top=70
Bottom=78

[Field 9]
Type=Button
Text=enter
Flags=NOTIFY
Left=225
Right=275
Top=92
Bottom=105

[Field 10]
Type=Label
Text=※ 
Enter four digits.
Left=0
Right=152
Top=26
Bottom=43

[Field 11]
Type=Label
Text=-
Left=154
Right=160
Top=68
Bottom=80

[Field 12]
Type=Label
Text=-
Left=199
Right=205
Top=68
Bottom=76

[Field 13]
Type=Label
Text=-
Left=110
Right=116
Top=68
Bottom=76

[Field 14]
Type=Label
Text=-
Left=64
Right=70
Top=68
Bottom=76

请帮助我。

documentation 中所述,您可以使用 MaxLen 选项。

示例:

[Field 1]
Type=Text
Text=1
Left=29
Right=275
Top=46
Bottom=57
MaxLen=4