本帖最后由 chzj589 于 2019-1-14 09:40 编辑
不好意思。昨天晚上家里小孩在捣乱,没经过测试就帖上来。重发代码:
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiComboBox.au3>
Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("窗")
Local $n = 2;这里简化了模型,实际上n数字很大,例如 n= 100
Local $combo_array[1 + $n]
;For $i = 1 To $n
;$combo_array[$i] = GUICtrlCreateCombo('', 150 * $i - 90, 10, 130, 30)
;GUICtrlSetOnEvent($combo_array[$i], "udf");==>==>==>==>==>==>==>==>==>==>此行是问题的核心
;GUICtrlSetOnEvent($combo_array[$i], "add")
;Next
$combo1 = GUICtrlCreateCombo('', 30, 10, 130, 30)
;GUICtrlSetOnEvent(-1, "_idCombo");"add")
$combo2 = GUICtrlCreateCombo('', 180, 10, 130, 30)
;GUICtrlSetOnEvent(-1, "_idCombo1");"add")
;对$combo_array赋值 注意,这里的字符都是无规律的,
GUICtrlSetData($combo1, '随机字符1|随机字符2|随机字符3')
GUICtrlSetData($combo2, '随机字符21|随机字符25|随机字符26|随机字符28')
ControlCommand($Form1, "", 'ComboBox1', "SetCurrentSelection", 0)
ControlCommand($Form1, "", 'ComboBox2', "SetCurrentSelection", 0)
$lable1 = GUICtrlCreateLabel('显示选择的结果', 30, 50, 20, 30)
$com1 = _GUICtrlComboBox_GetCurSel($combo1)
GUICtrlSetData($lable1, $com1)
$lable2 = GUICtrlCreateLabel('显示选择的结果', 180, 50, 20, 30)
$com2 = _GUICtrlComboBox_GetCurSel($combo2)
GUICtrlSetData($lable2, $com2)
$lablea2 = GUICtrlCreateLabel('', 220, 50, 20, 30)
$sComboRead = _GUICtrlComboBox_GetCount($combo2)
GUICtrlSetData($lablea2, $sComboRead)
;校验
$lable = GUICtrlCreateLabel('显示选择的结果', 10, 90, 200, 30)
$bt = GUICtrlCreateButton('按钮', 10, 150, 200, 40)
GUICtrlSetOnEvent($bt, "_idComboa");==>==>==>==>==>==>==>==>==>==>此行是问题的核心
GUISetOnEvent($GUI_EVENT_CLOSE, "QUIT")
GUISetState(@SW_SHOW)
While 1
Sleep(10)
WEnd
Func _idComboa()
; 获取项目数
; MsgBox(0, "消息", "项目数量: " & _GUICtrlComboBox_GetCount($combo2))
$sComboReada = _GUICtrlComboBox_GetCount($combo2)
$sComboRead = GUICtrlRead($lable2)
If $sComboRead = $sComboReada Then
GUICtrlSetData($lable2, "")
Else
$t = GUICtrlRead($lable2) + 1
GUICtrlSetData($lable2, $t)
ControlCommand($Form1, "", 'ComboBox2', "SetCurrentSelection", $t)
$temp = GUICtrlRead($combo2)
GUICtrlSetData($lable, $temp)
GUICtrlSetColor($lable, 0x009900); 背景色
GUICtrlSetFont($lable, 10, 600, 0, "微软雅黑")
EndIf
EndFunc ;==>_idComboa
Func QUIT()
Exit
EndFunc ;==>QUIT
|