无奈技术太差还得向高手请教—关于全选
#Include <Constants.au3>#Include <GUIConstantsEx.au3>
#Include <StaticConstants.au3>
#Include <TabConstants.au3>
#Include <WindowsConstants.au3>
If FileExists(@ScriptDir & "\Tab.ini") = 0 Then
MsgBox(64 + 0, "错误!", "请将配置文件放置于" & @ScriptDir & "\Tab.ini 再运行!")
Exit
EndIf
Dim $q = 0
Dim $Pic
Dim $with = 60
If $q >= 4 Then
Dim $max = $q
Else
Dim $max = 4
EndIf
Dim $Check[$max + 1]
GUICreate('MyGUI', 705, 409)
GUISetBkColor(0xFFFFFF)
GUICtrlCreatePic('img_bg.bmp', 0, 0, 705, 369)
GUICtrlSetState(-1, $GUI_DISABLE)
For $i = 0 To $max
$Pic[$i] = GUICtrlCreatePic(@ScriptDir & '\img_black.bmp', 10, 24 + 50 * $i, 162, 49)
GUICtrlCreateLabel('Tabsheet' & $i, 21, 40 + 50 * $i, 140, 18, $SS_CENTER)
GUICtrlSetFont(-1, 11, 400, 0, 'Tahoma')
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetcolor(-1, 0xFFFFFF)
Next
$Tab = GUICtrlCreateTab(172 + 4, 10 + 4, 523 - 8, 349 - 8)
GUICtrlSetState(-1, $GUI_DISABLE)
For $t = 0 To $max
GUICtrlCreateTabItem('Tabsheet' & $t)
For $i = 1 To $max
$Check[$i] = GUICtrlCreateCheckbox("", 182, 51 + $with * ($i - 1), 13, 13);建立Checkbox
If IniRead(@ScriptDir & "\Tab.ini", "tab" & $t, "Checkbox" & $i, "") = 1 Then
GUICtrlSetState($Check[$i], $GUI_CHECKED)
EndIf
Next
Next
GUICtrlCreateTabItem('')
$Label1 = GUICtrlCreateLabel("0", 23, 382, 100, 14)
$Checkbox1 = GUICtrlCreateCheckbox(" 全选/不选", 326, 382, 80, 14)
GUISetState()
$Item = -1
$Over = -1
While 1
$Info = GUIGetCursorInfo()
If @error Then
If $Over <> -1 Then
GUICtrlSetImage($Pic[$Over], @ScriptDir & '\img_black.bmp')
EndIf
$Over = -1
Else
$Index = _Index($Info)
If $Index <> $Over Then
If $Over <> -1 Then
GUICtrlSetImage($Pic[$Over], @ScriptDir & '\img_black.bmp')
EndIf
If ($Index <> -1) And ($Index <> $Item) Then
GUICtrlSetImage($Pic[$Index], @ScriptDir & '\img_over.bmp')
$Over = $Index
Else
$Over = -1
EndIf
EndIf
EndIf
$Msg = GUIGetMsg()
If $Item = -1 Then
$Msg = $Pic
$Item = 1
EndIf
Switch $Msg
Case 0
ContinueLoop
Case $GUI_EVENT_CLOSE
Exit
Case $Pic To $Pic
If $Msg <> $Pic[$Item] Then
GUICtrlSetImage($Pic[$Item], @ScriptDir & '\img_black.bmp')
GUICtrlSetcolor($Pic[$Item] + 1, 0xFFFFFF)
GUICtrlSetImage($Msg, @ScriptDir & '\img_white.bmp')
GUICtrlSetcolor($Msg + 1, 0x313A42)
$Item = _Index($Msg)
GUICtrlSendMsg($Tab, $TCM_SETCURFOCUS, $Item, 0)
$Over = -1
$Label1 = GUICtrlCreateLabel(GUICtrlRead($tab), 23, 382, 100, 14)
EndIf
Case $Checkbox1
Beep(1000, 50)
all()
EndSwitch
WEnd
Func _Index($CtrlID)
For $i = 0 To UBound($Pic) - 1
If ($CtrlID = $Pic[$i]) Or ($CtrlID = $Pic[$i] + 1) Then
Return $i
EndIf
Next
Return -1
EndFunc ;==>_Index
Func all()
$B = GUICtrlRead($Label1)
For $i = 1 To $max
If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
IniWrite(@ScriptDir & "\Tab.ini", "tab" & $B, "Checkbox" & $i, "1")
GUICtrlSetState($Check[$i], $GUI_CHECKED)
Else
GUICtrlSetState($Check[$i], $GUI_UNCHECKED)
IniWrite(@ScriptDir & "\Tab.ini", "tab" & $B, "Checkbox" & $i, "")
EndIf
Next
EndFunc ;==>all
ini 文件的读取和写入都没问题,但就是切换标签后,点击“全选/不选“后,Checkbox 不会随之变化,我想问题就出在 Func all()
这一块的。可由于刚学AU3 水平有限,还请高手不吝赐教!
netegg有篇文章可以看看不知道对你帮助大部大
http://www.autoitx.com/forum.php?mod=viewthread&tid=23547&highlight=%B8%B4%D1%A1%2B%B7%B4%D1%A1 真遗憾,无人解我心中烦忧,耐心等候ing... 笨办法!主要还是你的代码逻辑有点乱,同一个数组进行了多次赋值。
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
If FileExists(@ScriptDir & "\Tab.ini") = 0 Then
MsgBox(64 + 0, "错误!", "请将配置文件放置于" & @ScriptDir & "\Tab.ini 再运行!")
Exit
EndIf
Dim $q = 0
Dim $Pic
Dim $with = 60
Dim $x, $y
If $q >= 4 Then
Dim $max = $q
Else
Dim $max = 4
EndIf
Global $Check[$max + 1]
GUICreate('MyGUI', 705, 409)
GUISetBkColor(0xFFFFFF)
GUICtrlCreatePic('img_bg.bmp', 0, 0, 705, 369)
GUICtrlSetState(-1, $GUI_DISABLE)
For $i = 0 To $max
$Pic[$i] = GUICtrlCreatePic(@ScriptDir & '\img_black.bmp', 10, 24 + 50 * $i, 162, 49)
GUICtrlCreateLabel('Tabsheet' & $i, 21, 40 + 50 * $i, 140, 18, $SS_CENTER)
GUICtrlSetFont(-1, 11, 400, 0, 'Tahoma')
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, 0xFFFFFF)
Next
$Tab = GUICtrlCreateTab(172 + 4, 10 + 4, 523 - 8, 349 - 8)
GUICtrlSetState(-1, $GUI_DISABLE)
For $t = 0 To $max
GUICtrlCreateTabItem('Tabsheet' & $t)
For $i = 1 To $max
$Check[$i] = GUICtrlCreateCheckbox("", 182, 51 + $with * ($i - 1), 13, 13);建立Checkbox
If IniRead(@ScriptDir & "\Tab.ini", "tab" & $t, "Checkbox" & $i, "") = 1 Then
GUICtrlSetState($Check[$i], $GUI_CHECKED)
EndIf
If $x='' Then $x=$Check
Next
Next
$y = $Check[$max]
GUICtrlCreateTabItem('')
$Label1 = GUICtrlCreateLabel("0", 23, 382, 100, 14)
$Checkbox1 = GUICtrlCreateCheckbox(" 全选/不选", 326, 382, 80, 14)
GUISetState()
$Item = -1
$Over = -1
While 1
$Info = GUIGetCursorInfo()
If @error Then
If $Over <> -1 Then
GUICtrlSetImage($Pic[$Over], @ScriptDir & '\img_black.bmp')
EndIf
$Over = -1
Else
$Index = _Index($Info)
If $Index <> $Over Then
If $Over <> -1 Then
GUICtrlSetImage($Pic[$Over], @ScriptDir & '\img_black.bmp')
EndIf
If ($Index <> -1) And ($Index <> $Item) Then
GUICtrlSetImage($Pic[$Index], @ScriptDir & '\img_over.bmp')
$Over = $Index
Else
$Over = -1
EndIf
EndIf
EndIf
$Msg = GUIGetMsg()
If $Item = -1 Then
$Msg = $Pic
$Item = 1
EndIf
Switch $Msg
Case 0
ContinueLoop
Case -3
Exit
Case $Pic To $Pic
If $Msg <> $Pic[$Item] Then
GUICtrlSetImage($Pic[$Item], @ScriptDir & '\img_black.bmp')
GUICtrlSetColor($Pic[$Item] + 1, 0xFFFFFF)
GUICtrlSetImage($Msg, @ScriptDir & '\img_white.bmp')
GUICtrlSetColor($Msg + 1, 0x313A42)
$Item = _Index($Msg)
GUICtrlSendMsg($Tab, $TCM_SETCURFOCUS, $Item, 0)
$Over = -1
$Label1 = GUICtrlCreateLabel(GUICtrlRead($Tab), 23, 382, 100, 14)
EndIf
Case $Checkbox1
;Beep(1000, 50)
all()
EndSwitch
WEnd
Func _Index($CtrlID)
For $i = 0 To UBound($Pic) - 1
If ($CtrlID = $Pic[$i]) Or ($CtrlID = $Pic[$i] + 1) Then
Return $i
EndIf
Next
Return -1
EndFunc ;==>_Index
Func all()
$B = GUICtrlRead($Label1)
For $i = $x To $y
If GUICtrlRead($Checkbox1) = 1 Then
;IniWrite(@ScriptDir & "\Tab.ini", "tab" & $B, "Checkbox" & $i, "1")
GUICtrlSetState($i, 1)
Else
GUICtrlSetState($i, 4)
;IniWrite(@ScriptDir & "\Tab.ini", "tab" & $B, "Checkbox" & $i, "")
EndIf
Next
EndFunc ;==>all 我也来研究下 感谢水木子大侠出手相助,但我不得不遗憾的说,这段代码虽然解决了全选的问题,但是tab标签失效了,无论点击哪个tab页效果都是一样的,还有无法写入ini文件,稍作修改后虽然也能写入,但是格式乱了。
尽管如此,我还是要感谢水木子大侠,毕竟给了我一个新的思路。
愿更多的大侠能参与进来。谢谢! 无人帮助还是不屑一顾 无人帮助还是不屑一顾 说实话 代码需整理
#Include <Constants.au3>
#Include <GUIConstantsEx.au3>
#Include <StaticConstants.au3>
#Include <TabConstants.au3>
#Include <WindowsConstants.au3>
If FileExists(@ScriptDir & "\Tab.ini") = 0 Then
MsgBox(64 + 0, "错误!", "请将配置文件放置于" & @ScriptDir & "\Tab.ini 再运行!")
Exit
EndIf
Dim $q = 0
Dim $Pic
Dim $with = 60
If $q >= 4 Then
Dim $max = $q
Else
Dim $max = 4
EndIf
Dim $Check[$max+1][$max + 1]
GUICreate('MyGUI', 705, 409)
GUISetBkColor(0xFFFFFF)
GUICtrlCreatePic('img_bg.bmp', 0, 0, 705, 369)
GUICtrlSetState(-1, $GUI_DISABLE)
For $i = 0 To $max
$Pic[$i] = GUICtrlCreatePic(@ScriptDir & '\img_black.bmp', 10, 24 + 50 * $i, 162, 49)
GUICtrlCreateLabel('Tabsheet' & $i, 21, 40 + 50 * $i, 140, 18, $SS_CENTER)
GUICtrlSetFont(-1, 11, 400, 0, 'Tahoma')
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetcolor(-1, 0xFFFFFF)
Next
$Tab = GUICtrlCreateTab(172 + 4, 10 + 4, 523 - 8, 349 - 8)
GUICtrlSetState(-1, $GUI_DISABLE)
For $t = 0 To $max
GUICtrlCreateTabItem('Tabsheet' & $t)
For $i = 1 To $max
$Check[$t][$i] = GUICtrlCreateCheckbox("", 182, 51 + $with * ($i - 1), 13, 13);建立Checkbox
If IniRead(@ScriptDir & "\Tab.ini", "tab" & $t, "Checkbox" & $i, "") = 1 Then
GUICtrlSetState($Check[$t][$i], $GUI_CHECKED)
EndIf
Next
Next
GUICtrlCreateTabItem('')
$Label1 = GUICtrlCreateLabel("0", 23, 382, 100, 14)
$Checkbox1 = GUICtrlCreateCheckbox(" 全选/不选", 326, 382, 80, 14)
GUISetState()
$Item = -1
$Over = -1
While 1
$Info = GUIGetCursorInfo()
If @error Then
If $Over <> -1 Then
GUICtrlSetImage($Pic[$Over], @ScriptDir & '\img_black.bmp')
EndIf
$Over = -1
Else
$Index = _Index($Info)
If $Index <> $Over Then
If $Over <> -1 Then
GUICtrlSetImage($Pic[$Over], @ScriptDir & '\img_black.bmp')
EndIf
If ($Index <> -1) And ($Index <> $Item) Then
GUICtrlSetImage($Pic[$Index], @ScriptDir & '\img_over.bmp')
$Over = $Index
Else
$Over = -1
EndIf
EndIf
EndIf
$Msg = GUIGetMsg()
If $Item = -1 Then
$Msg = $Pic
$Item = 1
EndIf
Switch $Msg
Case 0
ContinueLoop
Case $GUI_EVENT_CLOSE
Exit
Case $Pic To $Pic
If $Msg <> $Pic[$Item] Then
GUICtrlSetImage($Pic[$Item], @ScriptDir & '\img_black.bmp')
GUICtrlSetcolor($Pic[$Item] + 1, 0xFFFFFF)
GUICtrlSetImage($Msg, @ScriptDir & '\img_white.bmp')
GUICtrlSetcolor($Msg + 1, 0x313A42)
$Item = _Index($Msg)
GUICtrlSendMsg($Tab, $TCM_SETCURFOCUS, $Item, 0)
$Over = -1
$Label1 = GUICtrlCreateLabel(GUICtrlRead($tab), 23, 382, 100, 14)
EndIf
Case $Checkbox1
Beep(1000, 50)
all()
EndSwitch
WEnd
Func _Index($CtrlID)
For $i = 0 To UBound($Pic) - 1
If ($CtrlID = $Pic[$i]) Or ($CtrlID = $Pic[$i] + 1) Then
Return $i
EndIf
Next
Return -1
EndFunc ;==>_Index
Func all()
$B =GUICtrlRead($Label1)
For $i = 1 To $max
If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
IniWrite(@ScriptDir & "\Tab.ini", "tab" & $B, "Checkbox" & $i, "1")
GUICtrlSetState($Check[$B][$i], $GUI_CHECKED)
Else
GUICtrlSetState($Check[$B][$i], $GUI_UNCHECKED)
IniWrite(@ScriptDir & "\Tab.ini", "tab" & $B, "Checkbox" & $i, "")
EndIf
Next
EndFunc ;==>all {:face (356):}哈哈,学习了。 不是不想帮,是没看懂你什么意思 我只能來學學人家的邏輯,自己沒有多少時間仔細看了 现在看见代码就烦。
页:
[1]