[已解决]请教前辈们,Edit控件如何动态更新内容
本帖最后由 fpquenya 于 2010-10-28 10:29 编辑小弟参考自由天空安装器做了一个软件安装助手,如图:
我想实现右边的内容随着左边树形点击动作而动态更新:
1.勾选软件,则添加改软件内容
2.反勾选软件,则删除该软件内容
望哪位大大帮忙给点思路,非常感谢! guictrlsetdata 回复 2# xianhou
谢谢回复,可能我没有表述清楚.我想要的是动态更新内容,用户可能勾选后又取消勾选,右边应该能正确反应这种变化.
如勾选了winRAR就添加,取消勾选winRAR,就要删除最上面一行的winRAR 本帖最后由 水木子 于 2010-10-28 10:13 编辑
#include <GUIListBox.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
Local $sConfigPath = @ScriptDir & '\Config.ini'
Local $f = -1, $s = -1
$aRegFitem = StringRegExp(FileRead($sConfigPath), '\[.+\]', 3)
$aRegSitem = StringRegExp(FileRead($sConfigPath), '=', 3)
Local $aFitem, $aSitem
Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
$Form1 = GUICreate('TreeView', 600, 450)
$TreeView1 = GUICtrlCreateTreeView(5, 5, 200, 440, $iStyle, $WS_EX_CLIENTEDGE)
$List1 = GUICtrlCreateList('', 210, 5, 385, 300)
GUICtrlCreateGroup('', 210, 300, 385, 140)
$Label1 = GUICtrlCreateLabel('准备安装:', 230, 320, 360, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel('0.0%', 540, 350, 50, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Progress1 = GUICtrlCreateProgress(230, 350, 300, 20)
GUICtrlCreateLabel("安装路径:", 230, 398, 100, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("", 310, 398, 200, 21)
$But1 = GUICtrlCreateButton("开始", 520, 396, 60, 25, $WS_GROUP)
GUICtrlCreateGroup("", -99, -99, 1, 1)
ConfigRead()
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $aFitem To $aSitem ;父项目 $aFitem
If BitAND(GUICtrlRead($nMsg), $GUI_CHECKED) Then
$iSitemNumber = Number(_GUICtrlTreeView_GetChildCount($TreeView1, $nMsg))
For $i = $nMsg To $nMsg + $iSitemNumber
GUICtrlSetState($i, $GUI_CHECKED)
Next
Else
$iSitemNumber = Number(_GUICtrlTreeView_GetChildCount($TreeView1, $nMsg))
For $i = $nMsg To $nMsg + $iSitemNumber
GUICtrlSetState($i, $GUI_UNCHECKED)
Next
EndIf
;Case $aSitem To $aSitem ;子项目
If BitAND(GUICtrlRead($nMsg), $GUI_CHECKED) Then
$hFitemHandle = _GUICtrlTreeView_GetParentParam($TreeView1, $nMsg)
GUICtrlSetState($hFitemHandle, $GUI_CHECKED)
Else
$hFitemHandle = _GUICtrlTreeView_GetParentParam($TreeView1, $nMsg)
$iSitemNumber = Number(_GUICtrlTreeView_GetChildCount($TreeView1, $hFitemHandle))
For $i = $hFitemHandle To $hFitemHandle + $iSitemNumber
If GUICtrlRead($i) = $GUI_CHECKED Then ExitLoop
If $i = $hFitemHandle + $iSitemNumber Then GUICtrlSetState($hFitemHandle, $GUI_UNCHECKED)
Next
EndIf
$x = 1
$sItemText = ''
GUICtrlSetData($List1, '') ;清空List内所有数据
For $i = 0 To UBound($aSitem) - 1
If _GUICtrlTreeView_GetChecked($TreeView1, $aSitem[$i]) Then
GUICtrlSetData($List1, StringFormat("[%02d]", $x) & $aSitem[$i]) ;如果项目被勾选则写入List
$sItemText &= $aSitem[$i] & '|'
$x += 1
EndIf
Next
Case $But1
BeginInstall()
EndSwitch
WEnd
Func ConfigRead()
$var1 = IniReadSectionNames($sConfigPath)
If Not @error Then
For $i = 1 To $var1
$f += 1
$aFitem[$f] = GUICtrlCreateTreeViewItem($var1[$i], $TreeView1)
$aFitem[$f] = $var1[$i]
$var2 = IniReadSection($sConfigPath, $var1[$i])
For $n = 1 To $var2
$s += 1
$aSitem[$s] = GUICtrlCreateTreeViewItem($var2[$n], $aFitem[$f])
$aSitem[$s] = $var2[$n]
Next
Next
EndIf
EndFunc ;==>ConfigRead
Func BeginInstall()
$aLines = StringSplit($sItemText, '|', 2)
$iNumber1 = 100 / (UBound($aLines) - 1)
$iNumber2 = $iNumber1
For $i = 0 To UBound($aLines) - 2
GUICtrlSetData($Label1, '正在安装:' & $aLines[$i])
_GUICtrlListBox_ReplaceString($List1, $i, '[→]' & $aLines[$i])
_GUICtrlListBox_SetCurSel($List1, $i)
Sleep(800)
_GUICtrlListBox_ReplaceString($List1, $i, '' & $aLines[$i])
_GUICtrlListBox_SetCurSel($List1, $i)
GUICtrlSetData($Progress1, $iNumber1)
GUICtrlSetData($Label2, StringFormat('%.1f%', $iNumber1))
$iNumber1 += $iNumber2
Next
GUICtrlSetData($Label1, '安装完成')
EndFunc ;==>BeginInstall
Config.ini 如下
回复 4# 水木子
非常感谢水木子大侠!
好好学习下您的代码! 回复 4# 水木子
我还没有看帖子的内容就知道你肯定会出来的!谁知道一看,果然你出来了!
你强人一个也! 这也猜得到 你也是强人!
页:
[1]