You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NSIS组件页复选框实现单选效果且默认选中指定组件问题

带单选效果的NSIS组件页

修复方案

针对你遇到的两个问题,对应修改逻辑如下:

  • 主组件被意外取消:在.onSelChange开头强制锁定主组件的选中、只读属性,避免单选组操作修改主组件状态
  • 初始选中状态不识别:.onSelChange仅响应用户手动操作,需在.onInit末尾手动调用一次该函数完成单选组初始化

修复后完整代码:

!include "MUI2.nsh"
!include "Sections.nsh"
OutFile "ABC.exe"
Name "ABC 1.0"

!insertmacro MUI_PAGE_COMPONENTS

Section "!ABC main" SEC_main
SectionEnd

Section /o "ABC expansion 1" SEC_exp1
SectionEnd

Section /o "ABC expansion 2" SEC_exp2
SectionEnd

Section /o "ABC expansion 3" SEC_exp3
SectionEnd

Section /o "ABC expansion 4" SEC_exp4
SectionEnd

Section /o "ABC expansion 5" SEC_exp5
SectionEnd

 Function .onSelChange
  ; 锁定主组件状态,禁止被取消
  SectionSetFlags ${SEC_main} 25
  !insertmacro StartRadioButtons $1
      !insertmacro RadioButton ${SEC_exp1}
      !insertmacro RadioButton ${SEC_exp2}
      !insertmacro RadioButton ${SEC_exp3}
      !insertmacro RadioButton ${SEC_exp4}
      !insertmacro RadioButton ${SEC_exp5}
  !insertmacro EndRadioButtons
 FunctionEnd

 Function .onInit
  SectionSetFlags ${SEC_main} 25
  SectionSetFlags ${SEC_exp3} 1
  ; 初始化单选组状态
  Call .onSelChange
FunctionEnd

编译运行后即可实现预期效果:主组件默认选中且无法取消,扩展组件互斥单选,启动时默认选中第三个扩展组件。

内容的提问来源于stack exchange,提问作者Kardaw

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 23:54:03