本帖最后由 fengjie 于 2014-3-24 00:33 编辑
问题已经解决,谢谢楼下的几位高手!简化后的代码看着就是舒服啊!
本菜鸟想请教大家一个问题,如下Switch条件选择语句代码能否简化?
代码如下:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=D:\百度云同步盘\Autoit\Checkbox_FontStyle_Test.kxf
$Form1 = GUICreate("字体设置测试", 285, 167, 192, 124)
$Checkbox1 = GUICtrlCreateCheckbox("粗体", 24, 24, 41, 17)
$Checkbox2 = GUICtrlCreateCheckbox("斜体", 80, 24, 41, 17)
$Checkbox3 = GUICtrlCreateCheckbox("下划线", 136, 24, 57, 17)
$Checkbox4 = GUICtrlCreateCheckbox("删除线", 208, 24, 57, 17)
$Button1 = GUICtrlCreateButton("查看字体代码", 96, 104, 83, 25)
$Label1 = GUICtrlCreateLabel("读取当前设置的字体", 88, 72, 112, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;初始化字体样式 0=普通 1=粗体 2=斜体 4=下划线 8=删除线
$FontStyle = "0"
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Checkbox1
If BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) = 1 Then
$FontStyle = $FontStyle + 1
Else
$FontStyle = $FontStyle - 1
EndIf
GUICtrlSetFont($Label1, 10, 400, $FontStyle, "微软雅黑")
Case $Checkbox2
If BitAND(GUICtrlRead($Checkbox2), $GUI_CHECKED) = 1 Then
$FontStyle = $FontStyle + 2
Else
$FontStyle = $FontStyle - 2
EndIf
GUICtrlSetFont($Label1, 10, 400, $FontStyle, "微软雅黑")
Case $Checkbox3
If BitAND(GUICtrlRead($Checkbox3), $GUI_CHECKED) = 1 Then
$FontStyle = $FontStyle + 4
Else
$FontStyle = $FontStyle - 4
EndIf
GUICtrlSetFont($Label1, 10, 400, $FontStyle, "微软雅黑")
Case $Checkbox4
If BitAND(GUICtrlRead($Checkbox4), $GUI_CHECKED) = 1 Then
$FontStyle = $FontStyle + 8
Else
$FontStyle = $FontStyle - 8
EndIf
GUICtrlSetFont($Label1, 10, 400, $FontStyle, "微软雅黑")
Case $Button1
MsgBox("", "字体设置测试", "当前字体设置的编号为:" & $FontStyle, 100)
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
运行效果:
目的:
实时取得$FontStyle的值,并根据此值设置Label1的字体样式
问题:
以上Switch条件选择语句相关代码能否简化?如果可以,该如何修改?谢谢! |