本帖最后由 xiehuahere 于 2011-11-25 21:28 编辑
回复 1# 网络小僧
可能丑陋一点,仅供参考:#Include <GuiEdit.au3>
#Include <GuiListBox.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$sIni=@TempDir&"\temp.ini"
$sData = "Key1=下拉A" & @LF & "Key2=下拉B" & @LF & "Key3=下拉C"
If Not FileExists(@TempDir&"\temp.ini") Then IniWriteSection($sIni, "Section", $sData)
$Form1 = GUICreate("Form1", 280, 134, 192, 124)
$Edit1 = GUICtrlCreateEdit("", 24, 40, 153, 25, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xffffff)
$var = IniReadSection($sIni, "section")
If @error Then MsgBox(4096, "", "错误, 读取INI文件失败.")
GUICtrlSetData(-1, $var[1][1])
$Button1 = GUICtrlCreateButton("Button1", 192, 38, 57, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$list = -1
$isSelected = 0
$index = -1
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
GUICtrlSetState($Button1, $GUI_DISABLE)
If $var[0][0] <> 0 Then
$list = GUICtrlCreateList("", 24, 65, 153, 18*$var[0][0], -1, $WS_EX_STATICEDGE)
GUICtrlSetBkColor(-1, 0xffffff)
$data = ""
For $i = 1 To $var[0][0]
$data &= $var[$i][1] & '|'
Next
If $index = -1 Then
GUICtrlSetData(-1, $data, $var[1][1])
Else
GUICtrlSetData(-1, $data, $var[$index+1][1])
EndIf
EndIf
Case $GUI_EVENT_PRIMARYDOWN
If $list <> -1 Then
$Pos = GUIGetCursorInfo($Form1)
If $Pos[4] = $list Then
$isSelected = 1
$index = _GUICtrlListBox_GetCurSel($list)
GUICtrlSetData($Edit1, _GUICtrlListBox_GetText(GUICtrlGetHandle($list), $index))
EndIf
EndIf
Case $GUI_EVENT_PRIMARYUP
If $list <> -1 And $isSelected Then
$index = _GUICtrlListBox_GetCurSel($list)
GUICtrlSetData($Edit1, _GUICtrlListBox_GetText(GUICtrlGetHandle($list), $index))
GUICtrlDelete($list)
$list = -1
$isSelected = 0
GUICtrlSetState($Button1, $GUI_ENABLE)
EndIf
EndSwitch
WEnd
【方法二】
我暂时还不会。 |