华杰 发表于 2008-6-3 14:58:32

帮助代码简化,有规律的相同点击如何简化。

参见代码。有方法的朋友请出手帮忙!:face (29):

#include <GUIConstants.au3>
Dim         $okDDgiu_Label,$okDDgiu_Input,$okDDgiu_Checkbox
    $okDDgiu = GUICreate("测试", 633, 515, -1, 0, BitOR($WS_CAPTION, $WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS))
        $okDDgiu_Label = GUICtrlCreateLabel("Label1", 34, 64, 100, 34)
        $okDDgiu_Label = GUICtrlCreateLabel("Label2", 34, 96, 100, 34)
        $okDDgiu_Label = GUICtrlCreateLabel("Label3", 34, 128, 100, 34)
        $okDDgiu_Label = GUICtrlCreateLabel("Label4", 34, 160, 100, 34)
        $okDDgiu_Label = GUICtrlCreateLabel("Label5", 34, 192, 100, 34)
        $okDDgiu_Label = GUICtrlCreateLabel("Label6", 34, 224, 100, 34)
        $okDDgiu_Label = GUICtrlCreateLabel("Label7", 34, 256, 100, 34)
        $okDDgiu_Label = GUICtrlCreateLabel("Label8", 34, 288, 100, 34)
        $okDDgiu_Label = GUICtrlCreateLabel("Label9", 34, 320, 100, 34)
        $okDDgiu_Label = GUICtrlCreateLabel("Label10", 34, 352, 100, 34)
        $okDDgiu_Label = GUICtrlCreateLabel("Label11", 296, 64, 100, 34)
        $okDDgiu_Label = GUICtrlCreateLabel("Label12", 296, 96, 100, 34)
        $okDDgiu_Label = GUICtrlCreateLabel("Label13", 296, 128, 100, 34)
        $okDDgiu_Label = GUICtrlCreateLabel("Label14", 296, 160, 100, 34)
        $okDDgiu_Label = GUICtrlCreateLabel("Label15", 296, 192, 100, 34)
        $okDDgiu_Label = GUICtrlCreateLabel("Label16", 296, 224, 100, 34)
        $okDDgiu_Label = GUICtrlCreateLabel("Label17", 296, 256, 100, 34)
        $okDDgiu_Label = GUICtrlCreateLabel("Label18", 296, 288, 100, 34)
        $okDDgiu_Label = GUICtrlCreateLabel("Label19", 296, 320, 100, 34)
        $okDDgiu_Label = GUICtrlCreateLabel("Label20", 296, 352, 100, 34)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 112, 56, 121, 21)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 112, 88, 121, 21)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 112, 120, 121, 21)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 112, 152, 121, 21)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 112, 184, 121, 21)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 112, 216, 121, 21)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 112, 248, 121, 21)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 112, 280, 121, 21)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 112, 312, 121, 21)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 112, 344, 121, 21)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 408, 56, 121, 21)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 408, 88, 121, 21)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 408, 120, 121, 21)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 408, 152, 121, 21)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 408, 184, 121, 21)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 408, 216, 121, 21)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 408, 248, 121, 21)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 408, 280, 121, 21)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 408, 312, 121, 21)
        $okDDgiu_Input = GUICtrlCreateCombo("请选择", 408, 344, 121, 21)
        $okDDgiu_Button1 = GUICtrlCreateButton("确认", 152, 464, 75, 33, 0)
        $okDDgiu_Button2 = GUICtrlCreateButton("关闭", 400, 464, 75, 33, 0)

        $okDDgiu_Edit1 = GUICtrlCreateEdit("", 112, 384, 417, 73)
        $okDDgiu_Label21 = GUICtrlCreateLabel("备注:", 34, 416, 43, 17)

$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 240, 56, 17, 17)
$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 240, 88, 17, 17)
$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 240, 120, 17, 17)
$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 240, 152, 17, 17)
$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 240, 184, 17, 17)
$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 240, 216, 17, 17)
$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 240, 248, 17, 17)
$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 240, 280, 17, 17)
$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 240, 312, 17, 17)
$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 240, 344, 17, 17)
$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 536, 56, 17, 17)
$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 536, 88, 17, 17)
$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 536, 120, 17, 17)
$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 536, 152, 17, 17)
$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 536, 184, 17, 17)
$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 536, 216, 17, 17)
$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 536, 248, 17, 17)
$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 536, 280, 17, 17)
$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 536, 312, 17, 17)
$okDDgiu_Checkbox = GUICtrlCreateCheckbox("", 536, 344, 17, 17)
$okDDgiu_Label21 = GUICtrlCreateLabel("类型:", 32, 8, 31, 17)
$okDDgiu_Label22 = GUICtrlCreateLabel("非配套下单", 72, 8, 64, 17)
$okDDgiu_Label23 = GUICtrlCreateLabel("部件名称", 32, 32, 52, 17)
$okDDgiu_Label24 = GUICtrlCreateLabel("数量(单位:PCS)", 120, 32, 91, 17)
$okDDgiu_Label25 = GUICtrlCreateLabel("配/不配", 224, 32, 45, 17)
$okDDgiu_Label26 = GUICtrlCreateLabel("部件名称", 296, 32, 52, 17)
$okDDgiu_Label27 = GUICtrlCreateLabel("数量(单位:PCS)", 416, 32, 91, 17)
$okDDgiu_Label28 = GUICtrlCreateLabel("配/不配", 520, 32, 45, 17)
        GUISetState(@SW_SHOW)
        #EndRegion ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\桌面\Form3.kxf
        While 1
                $nMsg = GUIGetMsg()
                Select
                        Case $nMsg = $GUI_EVENT_CLOSE Or $nMsg =$okDDgiu_Button2
Exit
                        Case $nMsg = $okDDgiu_Checkbox;后面还有$okDDgiu_Checkbox请问如何简化?不可能这样重复代码吧?请有方法的朋友出手。多谢
                        If        BitAND(GUICtrlRead($okDDgiu_Checkbox), $GUI_CHECKED) = $GUI_CHECKED Then
                        GUICtrlSetState($okDDgiu_Input, $GUI_ENABLE)
                        GUICtrlSetData($okDDgiu_Input, "")
                        GUICtrlSetState($okDDgiu_Label, $GUI_ENABLE)
                Else
                        GUICtrlSetState($okDDgiu_Input, $GUI_DISABLE)
                        GUICtrlSetData($okDDgiu_Input, "")
                        GUICtrlSetState($okDDgiu_Label, $GUI_DISABLE)                       
                EndIf
EndSelect
WEnd

[ 本帖最后由 华杰 于 2008-6-3 19:45 编辑 ]

netegg 发表于 2008-6-3 15:23:15

用数组呗,应该不是很难吧,关键是操作,如果也差不多的话,肯定用数组,如果操作不一样的话,可能会麻烦点,不过可以用select $msg来做,不过要动点心思,坐标用个循环就行了

[ 本帖最后由 netegg 于 2008-6-3 15:27 编辑 ]

华杰 发表于 2008-6-3 15:48:05

能否给出具体代码。多谢

firewzy 发表于 2008-6-3 17:05:07

原帖由 华杰 于 2008-6-3 14:58 发表 http://www.autoitx.com/images/common/back.gif
参见代码。有方法的朋友请出手帮忙!:face (29):
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Dim $okDDgiu_Label,$okDDgiu_Input,$okDDgiu_Checkbox;
Dim $Int_ChkIndex = 0, $Int_CtrlIndex = 0;

$okDDgiu = GUICreate("测试", 633, 515, -1, 0, BitOR($WS_CAPTION, $WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS))

$okDDgiu_Label21 = GUICtrlCreateLabel("类型:", 32, 8, 31, 17)
$okDDgiu_Label22 = GUICtrlCreateLabel("非配套下单", 72, 8, 64, 17)
$okDDgiu_Label23 = GUICtrlCreateLabel("部件名称", 32, 32, 52, 17)
$okDDgiu_Label24 = GUICtrlCreateLabel("数量(单位:PCS)", 120, 32, 91, 17)
$okDDgiu_Label25 = GUICtrlCreateLabel("配/不配", 224, 32, 45, 17)
$okDDgiu_Label26 = GUICtrlCreateLabel("部件名称", 328, 32, 52, 17)
$okDDgiu_Label27 = GUICtrlCreateLabel("数量(单位:PCS)", 416, 32, 91, 17)
$okDDgiu_Label28 = GUICtrlCreateLabel("配/不配", 520, 32, 45, 17)

For $Int_CtrlIndex = 1 To 20

        If $Int_CtrlIndex <= 10 Then
                $okDDgiu_Label[$Int_CtrlIndex] = GUICtrlCreateLabel("Label" & $Int_CtrlIndex, 34, 56+32*($Int_CtrlIndex-1), 100, 34)
        Else
                $okDDgiu_Label[$Int_CtrlIndex] = GUICtrlCreateLabel("Label" & $Int_CtrlIndex, 328, 56+32*($Int_CtrlIndex-11), 100, 34)
        EndIf

Next

For $Int_CtrlIndex = 1 To 20

        If $Int_CtrlIndex <= 10 Then
                $okDDgiu_Input[$Int_CtrlIndex] = GUICtrlCreateCombo("请选择", 112, 56+32*($Int_CtrlIndex-1), 121, 21)
        Else
                $okDDgiu_Input[$Int_CtrlIndex] = GUICtrlCreateCombo("请选择", 408, 56+32*($Int_CtrlIndex-11), 121, 21)
        EndIf

Next

For $Int_CtrlIndex = 1 To 20

        If $Int_CtrlIndex <= 10 Then
                $okDDgiu_Checkbox[$Int_CtrlIndex] = GUICtrlCreateCheckbox("", 240, 56+32*($Int_CtrlIndex-1), 17, 17)
        Else
                $okDDgiu_Checkbox[$Int_CtrlIndex] = GUICtrlCreateCheckbox("", 536, 56+32*($Int_CtrlIndex-11), 17, 17)
        EndIf

Next

$okDDgiu_Label21 = GUICtrlCreateLabel("备注:", 34, 416, 43, 17)
$okDDgiu_Edit1 = GUICtrlCreateEdit("", 112, 384, 417, 73)

$okDDgiu_Button1 = GUICtrlCreateButton("确认", 152, 464, 75, 33, 0)
$okDDgiu_Button2 = GUICtrlCreateButton("关闭", 400, 464, 75, 33, 0)

For $Int_CtrlIndex = 1 To 20
        GUICtrlSetState($okDDgiu_Input[$Int_CtrlIndex], $GUI_DISABLE)
Next

GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()

        Select
                Case $nMsg = $GUI_EVENT_CLOSE Or $nMsg =$okDDgiu_Button2
                        Exit
                Case $nMsg >= $okDDgiu_Checkbox And $nMsg <= $okDDgiu_Checkbox
                        $Int_ChkIndex = $nMsg - $okDDgiu_Checkbox + 1

                        If BitAND(GUICtrlRead($okDDgiu_Checkbox[$Int_ChkIndex]), $GUI_CHECKED) = $GUI_CHECKED Then
                                GUICtrlSetState($okDDgiu_Input[$Int_ChkIndex], $GUI_ENABLE)
                                GUICtrlSetData($okDDgiu_Input[$Int_ChkIndex], "")
                        Else
                                GUICtrlSetState($okDDgiu_Input[$Int_ChkIndex], $GUI_DISABLE)
                                GUICtrlSetData($okDDgiu_Input[$Int_ChkIndex], "")                       
                        EndIf

        EndSelect

WEnd

316428696 发表于 2009-9-8 12:15:06

不错,支持你楼主
页: [1]
查看完整版本: 帮助代码简化,有规律的相同点击如何简化。