找回密码
 加入
搜索
查看: 1521|回复: 4

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

[复制链接]
发表于 2008-6-3 14:58:32 | 显示全部楼层 |阅读模式
参见代码。有方法的朋友请出手帮忙!

#include <GUIConstants.au3>
Dim         $okDDgiu_Label[21],$okDDgiu_Input[21],$okDDgiu_Checkbox[21]
    $okDDgiu = GUICreate("测试", 633, 515, -1, 0, BitOR($WS_CAPTION, $WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS))
        $okDDgiu_Label[1] = GUICtrlCreateLabel("Label1", 34, 64, 100, 34)
        $okDDgiu_Label[2] = GUICtrlCreateLabel("Label2", 34, 96, 100, 34)
        $okDDgiu_Label[3] = GUICtrlCreateLabel("Label3", 34, 128, 100, 34)
        $okDDgiu_Label[4] = GUICtrlCreateLabel("Label4", 34, 160, 100, 34)
        $okDDgiu_Label[5] = GUICtrlCreateLabel("Label5", 34, 192, 100, 34)
        $okDDgiu_Label[6] = GUICtrlCreateLabel("Label6", 34, 224, 100, 34)
        $okDDgiu_Label[7] = GUICtrlCreateLabel("Label7", 34, 256, 100, 34)
        $okDDgiu_Label[8] = GUICtrlCreateLabel("Label8", 34, 288, 100, 34)
        $okDDgiu_Label[9] = GUICtrlCreateLabel("Label9", 34, 320, 100, 34)
        $okDDgiu_Label[10] = GUICtrlCreateLabel("Label10", 34, 352, 100, 34)
        $okDDgiu_Label[11] = GUICtrlCreateLabel("Label11", 296, 64, 100, 34)
        $okDDgiu_Label[12] = GUICtrlCreateLabel("Label12", 296, 96, 100, 34)
        $okDDgiu_Label[13] = GUICtrlCreateLabel("Label13", 296, 128, 100, 34)
        $okDDgiu_Label[14] = GUICtrlCreateLabel("Label14", 296, 160, 100, 34)
        $okDDgiu_Label[15] = GUICtrlCreateLabel("Label15", 296, 192, 100, 34)
        $okDDgiu_Label[16] = GUICtrlCreateLabel("Label16", 296, 224, 100, 34)
        $okDDgiu_Label[17] = GUICtrlCreateLabel("Label17", 296, 256, 100, 34)
        $okDDgiu_Label[18] = GUICtrlCreateLabel("Label18", 296, 288, 100, 34)
        $okDDgiu_Label[19] = GUICtrlCreateLabel("Label19", 296, 320, 100, 34)
        $okDDgiu_Label[20] = GUICtrlCreateLabel("Label20", 296, 352, 100, 34)
        $okDDgiu_Input[1] = GUICtrlCreateCombo("请选择", 112, 56, 121, 21)
        $okDDgiu_Input[2] = GUICtrlCreateCombo("请选择", 112, 88, 121, 21)
        $okDDgiu_Input[3] = GUICtrlCreateCombo("请选择", 112, 120, 121, 21)
        $okDDgiu_Input[4] = GUICtrlCreateCombo("请选择", 112, 152, 121, 21)
        $okDDgiu_Input[5] = GUICtrlCreateCombo("请选择", 112, 184, 121, 21)
        $okDDgiu_Input[6] = GUICtrlCreateCombo("请选择", 112, 216, 121, 21)
        $okDDgiu_Input[7] = GUICtrlCreateCombo("请选择", 112, 248, 121, 21)
        $okDDgiu_Input[8] = GUICtrlCreateCombo("请选择", 112, 280, 121, 21)
        $okDDgiu_Input[9] = GUICtrlCreateCombo("请选择", 112, 312, 121, 21)
        $okDDgiu_Input[10] = GUICtrlCreateCombo("请选择", 112, 344, 121, 21)
        $okDDgiu_Input[11] = GUICtrlCreateCombo("请选择", 408, 56, 121, 21)
        $okDDgiu_Input[12] = GUICtrlCreateCombo("请选择", 408, 88, 121, 21)
        $okDDgiu_Input[13] = GUICtrlCreateCombo("请选择", 408, 120, 121, 21)
        $okDDgiu_Input[14] = GUICtrlCreateCombo("请选择", 408, 152, 121, 21)
        $okDDgiu_Input[15] = GUICtrlCreateCombo("请选择", 408, 184, 121, 21)
        $okDDgiu_Input[16] = GUICtrlCreateCombo("请选择", 408, 216, 121, 21)
        $okDDgiu_Input[17] = GUICtrlCreateCombo("请选择", 408, 248, 121, 21)
        $okDDgiu_Input[18] = GUICtrlCreateCombo("请选择", 408, 280, 121, 21)
        $okDDgiu_Input[19] = GUICtrlCreateCombo("请选择", 408, 312, 121, 21)
        $okDDgiu_Input[20] = 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[1] = GUICtrlCreateCheckbox("", 240, 56, 17, 17)
$okDDgiu_Checkbox[2] = GUICtrlCreateCheckbox("", 240, 88, 17, 17)
$okDDgiu_Checkbox[3] = GUICtrlCreateCheckbox("", 240, 120, 17, 17)
$okDDgiu_Checkbox[4] = GUICtrlCreateCheckbox("", 240, 152, 17, 17)
$okDDgiu_Checkbox[5] = GUICtrlCreateCheckbox("", 240, 184, 17, 17)
$okDDgiu_Checkbox[6] = GUICtrlCreateCheckbox("", 240, 216, 17, 17)
$okDDgiu_Checkbox[7] = GUICtrlCreateCheckbox("", 240, 248, 17, 17)
$okDDgiu_Checkbox[8] = GUICtrlCreateCheckbox("", 240, 280, 17, 17)
$okDDgiu_Checkbox[9] = GUICtrlCreateCheckbox("", 240, 312, 17, 17)
$okDDgiu_Checkbox[10] = GUICtrlCreateCheckbox("", 240, 344, 17, 17)
$okDDgiu_Checkbox[11] = GUICtrlCreateCheckbox("", 536, 56, 17, 17)
$okDDgiu_Checkbox[12] = GUICtrlCreateCheckbox("", 536, 88, 17, 17)
$okDDgiu_Checkbox[13] = GUICtrlCreateCheckbox("", 536, 120, 17, 17)
$okDDgiu_Checkbox[14] = GUICtrlCreateCheckbox("", 536, 152, 17, 17)
$okDDgiu_Checkbox[15] = GUICtrlCreateCheckbox("", 536, 184, 17, 17)
$okDDgiu_Checkbox[16] = GUICtrlCreateCheckbox("", 536, 216, 17, 17)
$okDDgiu_Checkbox[17] = GUICtrlCreateCheckbox("", 536, 248, 17, 17)
$okDDgiu_Checkbox[18] = GUICtrlCreateCheckbox("", 536, 280, 17, 17)
$okDDgiu_Checkbox[19] = GUICtrlCreateCheckbox("", 536, 312, 17, 17)
$okDDgiu_Checkbox[20] = 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[1];后面还有$okDDgiu_Checkbox[1-20]请问如何简化?不可能这样重复代码吧?请有方法的朋友出手。多谢
                        If        BitAND(GUICtrlRead($okDDgiu_Checkbox[1]), $GUI_CHECKED) = $GUI_CHECKED Then
                        GUICtrlSetState($okDDgiu_Input[1], $GUI_ENABLE)
                        GUICtrlSetData($okDDgiu_Input[1], "")
                        GUICtrlSetState($okDDgiu_Label[1], $GUI_ENABLE)
                Else
                        GUICtrlSetState($okDDgiu_Input[1], $GUI_DISABLE)
                        GUICtrlSetData($okDDgiu_Input[1], "")
                        GUICtrlSetState($okDDgiu_Label[1], $GUI_DISABLE)                        
                EndIf
EndSelect
WEnd


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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2008-6-3 15:23:15 | 显示全部楼层
用数组呗,应该不是很难吧,关键是操作,如果也差不多的话,肯定用数组,如果操作不一样的话,可能会麻烦点,不过可以用select $msg来做,不过要动点心思,坐标用个循环就行了

[ 本帖最后由 netegg 于 2008-6-3 15:27 编辑 ]
 楼主| 发表于 2008-6-3 15:48:05 | 显示全部楼层
能否给出具体代码。多谢
发表于 2008-6-3 17:05:07 | 显示全部楼层
原帖由 华杰 于 2008-6-3 14:58 发表
参见代码。有方法的朋友请出手帮忙!

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Dim $okDDgiu_Label[21],$okDDgiu_Input[21],$okDDgiu_Checkbox[21];
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[1] And $nMsg <= $okDDgiu_Checkbox[20]
                        $Int_ChkIndex = $nMsg - $okDDgiu_Checkbox[1] + 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

评分

参与人数 1金钱 +5 收起 理由
华杰 + 5 精品文章,高手。多谢

查看全部评分

发表于 2009-9-8 12:15:06 | 显示全部楼层
不错,支持你楼主
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-1 10:21 , Processed in 0.091083 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表