根据输入文字变换输入框背景颜色作指示

;nsDialogs根据输入文字变换输入框背景颜色作指示。根据输入的文本实现控制文本西式背景颜色会改变到黄色(没有输入)或红色(错误输入)。

Caption "根据输入文字变换输入框背景颜色作指示"
OutFile "ColorfulErrors.exe"
BrandingText "WwW.yhxs3344.Net"
loadlanguagefile "${NSISDIR}ContribLanguage filessimpChinese.nlf"
;includes
!include nsDialogs.nsh
!include LogicLib.nsh
;variables
Var Dialog
Var Directory
Var ButtonClear
Var ButtonReset
;definitions
!define YELLOW "0xfff799"
!define RED "0xf69679"
;页面
Page custom nsDialogsPage nsDialogsLeave
Page InstFiles
;函数
Function nsDialogsPage
 nsDialogs::Create /NOUNLOAD 1018
 Pop $Dialog
 ${If} $Dialog == error
 Abort
 ${EndIf}
 ${NSD_CreateLabel} 0 0 100% 65%
 "此例子使用背景颜色来显示文本框状态。要了解此例子,您可以:$n$n$t1. 修改或删除文本框内路径$n$t2. 点击清空按钮$n$t3. 点击重置按钮$n$n正如您所看到的,文本框背景颜色的变化取决于您的输入。错误的路径会显示红色、输入框置空会显示黄色。仅当路径为 $DESKTOP 会显示文本框默认的颜色。"
 ${NSD_CreateText} 0 65% 75% 20 "$DESKTOP"
 Pop $Directory
 ${NSD_OnChange} $Directory OnChange
 ${NSD_CreateButton} 78% 65% 10% 20 "清空"
 Pop $ButtonClear
 ${NSD_OnClick} $ButtonClear OnClickClear
 ${NSD_CreateButton} 90% 65% 10% 20 "重置"
 Pop $ButtonReset
 ${NSD_OnClick} $ButtonReset OnClickReset
 ${NSD_CreateLabel} 0 85% 100% 15% "PS: 但遗憾的是,您可能需离开控件时才看到效果!"
 nsDialogs::Show
FunctionEnd
Function nsDialogsLeave
 ${NSD_GetText} $Directory $0
 ${If} $0 == ""
 MessageBox MB_YESNO|MB_ICONEXCLAMATION "填入当前用户桌面路径,忽略?" IDYES +2
 Abort
 ${ElseIfNot} $0 == "$DESKTOP"
 MessageBox MB_YESNO|MB_ICONEXCLAMATION "并非当前用户桌面路径,忽略?" IDYES +2
 Abort
 ${EndIf}
FunctionEnd
Function OnChange
 Pop $0 # HWND
 ${NSD_GetText} $Directory $0
 ${If} $0 == ""
 SetCtlColors $Directory "" ${YELLOW}
 ${Else}
 ${If} ${FileExists} "$0*.*"
 SetCtlColors $Directory "" "" ;重置颜色
 ${Else}
 SetCtlColors $Directory "" ${RED}
 ${EndIf}
 ${EndIf}
FunctionEnd
Function OnClickClear
 Pop $0 # HWND
 ${NSD_SetText} $Directory ""
FunctionEnd
Function OnClickReset
 Pop $0 # HWND
 ${NSD_SetText} $Directory "$DESKTOP"
FunctionEnd
Section
 Quit
SectionEnd
© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容