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

[AU3基础] 【已解决】关于按键背景色如何取反

[复制链接]
发表于 2012-3-4 23:37:00 | 显示全部楼层 |阅读模式
本帖最后由 lm959680 于 2012-3-5 02:53 编辑

主要是想 点击后 改按键背景色 但如果再点击 变另一种色 只在两种颜色之间更换

想问问各位 有什么好的方法 用GUICtrlRead 无法得到按钮的背景颜色状态
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
Opt("GUIOnEventMode", 1)
Global $Button[65]
Global $x = 1, $y = 1
$Form1 = GUICreate("$Form1",342)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
        For $i = 1 To 64
        $Button[$i] = GUICtrlCreateButton("", ($x * 42) - 36, ($y * 38) - 30, 38, 35)
        ;GUICtrlSetBkColor(-1, 0x000000)
        GUICtrlSetBkColor(-1, 0xC0C0C0)
        GUICtrlSetOnEvent($Button[$i], "_ButtonXY")
        $x += 1
        If $x = 9 Then
                $x = 1
                Switch $y
                        Case 1
                                $y = 2
                        Case 2
                                $y = 3
                        Case 3
                                $y = 4
                        Case 4
                                $y = 5
                        Case 5
                                $y = 6
                        Case 6
                                $y = 7
                        Case 7
                                $y = 8
                        Case 8
                                $y = 9
                        Case 9
                                $y = 10
                EndSwitch
        EndIf
Next
GUISetState()

        
While 1
        Sleep(10)
WEnd


Func _ButtonXY()
                GUICtrlSetBkColor(@GUI_CtrlId, 0x000000)
EndFunc   ;==>_ButtonXY

Func Form1Close()
        Exit
EndFunc
发表于 2012-3-5 01:13:24 | 显示全部楼层
先声明 $Color[2] = [0xC0C0C0, 0]
再修改 _ButtonXY:
Func _ButtonXY()
        Assign('~' & @GUI_CtrlId, Not Eval('~' & @GUI_CtrlId), 2)
        GUICtrlSetBkColor(@GUI_CtrlId, $Color[Eval('~' & @GUI_CtrlId)])
EndFunc
即可,也就增加两行
发表于 2012-3-5 01:48:11 | 显示全部楼层
A版威武,顺便照猫画虎下:
Func _ButtonXY()
        If Eval('-' & @GUI_CtrlId) = '' Then
                GUICtrlSetBkColor(@GUI_CtrlId, 0x000000)
                Assign('-' & @GUI_CtrlId, 1,2)
        Else
                GUICtrlSetBkColor(@GUI_CtrlId, 0xC0C0C0)
                Assign('-' & @GUI_CtrlId, '',2)
        EndIf
EndFunc   ;==>_ButtonXY
 楼主| 发表于 2012-3-5 02:52:11 | 显示全部楼层
本帖最后由 lm959680 于 2012-3-5 02:59 编辑

多谢楼上两位 等不急 自己已写完了 版主太强大了···
#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>

Opt("GUIOnEventMode", 1)
Global $Button[65]
Global $x = 1, $y = 1
Global $txt
$Form1 = GUICreate("8*8点阵计算工具---随心飘渺", 342, 350)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
For $i = 1 To 64
        $Button[$i] = GUICtrlCreateButton("", ($x * 42) - 36, ($y * 38) - 30, 35, 35)
        ;GUICtrlSetBkColor(-1, 0x000000)
        GUICtrlSetBkColor(-1, 0xC0C0C0)
        GUICtrlSetOnEvent($Button[$i], "_ButtonXY")
        $x += 1
        $txt &= "0"
        If $x = 9 Then
                $x = 1
                Switch $y
                        Case 1
                                $y = 2
                        Case 2
                                $y = 3
                        Case 3
                                $y = 4
                        Case 4
                                $y = 5
                        Case 5
                                $y = 6
                        Case 6
                                $y = 7
                        Case 7
                                $y = 8
                        Case 8
                                $y = 9
                        Case 9
                                $y = 10
                EndSwitch
        EndIf
Next
$Input1 = GUICtrlCreateInput("", 1, 320, 340, 21)
GUICtrlSetStyle(-1, $ES_READONLY + $ES_CENTER)
GUISetState()

While 1
        Sleep(10)
WEnd


Func _ButtonXY()
        Local $var, $i, $result[9],$Hex
        $var = StringInStr($txt, "1", 0, 1, @GUI_CtrlId - 2, 1)
        If $var = 0 Then
                $txt = StringReplace($txt, @GUI_CtrlId - 2, "1")
                GUICtrlSetBkColor(@GUI_CtrlId, 0x000000)
        Else
                $txt = StringReplace($txt, @GUI_CtrlId - 2, "0")
                GUICtrlSetBkColor(@GUI_CtrlId, 0xC0C0C0)
        EndIf
$Hex=$txt
        For $i = 1 To 8
                $result[$i] = StringLeft($Hex, 8)
                $Hex = StringTrimLeft($Hex, 8)
                $result[$i] = _BinaryToHex($result[$i],2)
        Next
        For $i = 1 To 8
                $Hex = $Hex&"0x" & $result[$i] & ","
        Next
        GUICtrlSetData($Input1, $Hex)
EndFunc   ;==>_ButtonXY

Func Form1Close()
        Exit
EndFunc   ;==>Form1Close

Func _BinaryToHex($sBinStr, $iLength = 0)
        Local $sHexStr = ""
        If Not StringRegExp($sBinStr, "^[01]+$") Then Return SetError(1, 0, "")

        While Mod(StringLen($sBinStr), 4)
                $sBinStr = "0" & $sBinStr
        WEnd
        For $i = 1 To StringLen($sBinStr) Step 4
                Switch StringMid($sBinStr, $i, 4)
                        Case "0000"
                                $sHexStr &= "0"
                        Case "0001"
                                $sHexStr &= "1"
                        Case "0010"
                                $sHexStr &= "2"
                        Case "0011"
                                $sHexStr &= "3"
                        Case "0100"
                                $sHexStr &= "4"
                        Case "0101"
                                $sHexStr &= "5"
                        Case "0110"
                                $sHexStr &= "6"
                        Case "0111"
                                $sHexStr &= "7"
                        Case "1000"
                                $sHexStr &= "8"
                        Case "1001"
                                $sHexStr &= "9"
                        Case "1010"
                                $sHexStr &= "A"
                        Case "1011"
                                $sHexStr &= "B"
                        Case "1100"
                                $sHexStr &= "C"
                        Case "1101"
                                $sHexStr &= "D"
                        Case "1110"
                                $sHexStr &= "E"
                        Case "1111"
                                $sHexStr &= "F"
                EndSwitch
        Next

        If $iLength = 0 Then
                While StringLeft($sHexStr, 1) = "0"
                        $sHexStr = StringTrimLeft($sHexStr, 1)
                WEnd
        Else
                For $i = 1 To $iLength - StringLen($sHexStr)
                        $sHexStr = "0" & $sHexStr
                Next
        EndIf

        Return $sHexStr
EndFunc   ;==>_BinaryToHex
发表于 2012-8-2 17:16:47 | 显示全部楼层
菜鸟路过,偷回家研究呵呵,多谢了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-30 03:24 , Processed in 0.089151 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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