[已解决]修改控件颜色遇到麻烦,脑子不够用了....
本帖最后由 guland 于 2010-8-14 11:45 编辑我想做的是点击一下按钮当前控件恢复成原来的颜色,然后下一个控件变成黄色
就想图片中的一样,现在1是黄色,其它的都是白色,点击按钮一次1变成包白色,2变成黄色,以此类推
研究N久没搞明白怎么弄,黄色的部分是Label,那些框是Group,只需要改变Label的背景色就可以了
谢谢大家回复,我的问题没有说清楚,补充一下,我的窗口是要放在func里面的
谢谢大家的解答,最后我用数组加FOR搞定了,代码真实精简一多半啊......... 帮顶 我不会 本帖最后由 水木子 于 2010-8-14 10:56 编辑
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
GUICreate("Form1", 300, 400)
$Label1 = GUICtrlCreateLabel("", 50, 40, 50, 30)
GUICtrlSetBkColor(-1, 0xFFFF00)
$Label2 = GUICtrlCreateLabel("", 50, 100, 50, 30)
GUICtrlSetBkColor(-1, 0xFFFF00)
$Label3 = GUICtrlCreateLabel("", 50, 160, 50, 30)
GUICtrlSetBkColor(-1, 0xFFFF00)
$Label4 = GUICtrlCreateLabel("", 50, 220, 50, 30)
GUICtrlSetBkColor(-1, 0xFFFF00)
GUICtrlCreateGroup("Group1", 40, 24, 70, 55)
GUICtrlCreateGroup("Group2", 40, 84, 70, 55)
GUICtrlCreateGroup("Group3", 40, 144, 70, 55)
GUICtrlCreateGroup("Group4", 40, 204, 70, 55)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case - 3
Exit
Case $Label1 To $Label4
If Eval('!' & $nMsg) = '' Then
GUICtrlSetBkColor($nMsg, 0x00ff00) ;绿色
Assign('!' & $nMsg, 1)
Else
GUICtrlSetBkColor($nMsg, 0xFFFF00) ;黄色
Assign('!' & $nMsg, '')
EndIf
EndSwitch
WEnd 本帖最后由 Ziya 于 2010-8-14 10:17 编辑
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
GUICreate("Form1", 300, 400)
$Label1 = GUICtrlCreateLabel("", 50, 40, 50, 30)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Label2 = GUICtrlCreateLabel("", 50, 100, 50, 30)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Label3 = GUICtrlCreateLabel("", 50, 160, 50, 30)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Label4 = GUICtrlCreateLabel("", 50, 220, 50, 30)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlCreateGroup("Group1", 40, 24, 70, 55)
GUICtrlCreateGroup("Group2", 40, 84, 70, 55)
GUICtrlCreateGroup("Group3", 40, 144, 70, 55)
GUICtrlCreateGroup("Group4", 40, 204, 70, 55)
$Button1 = GUICtrlCreateButton("Button1", 176, 56, 75, 25)
GUISetState()
Local $L
$L = ""
$L =$Label1
$L =$Label2
$L =$Label3
$L =$Label4
$a = 0
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case - 3
Exit
Case $Button1
If $a = 4 Then
GUICtrlSetBkColor($L[$a], 0xFFFFFF)
$a = 0
Else
GUICtrlSetBkColor($L[$a], 0xFFFFFF)
GUICtrlSetBkColor($L[$a + 1], 0xffff00)
$a += 1
EndIf
EndSwitch
WEnd来个笨方法的..... #include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
GUICreate("Form1", 300, 400)
$Label1 = GUICtrlCreateLabel("", 50, 40, 50, 30)
GUICtrlSetBkColor(-1, 0xffff00)
$Label2 = GUICtrlCreateLabel("", 50, 100, 50, 30)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Label3 = GUICtrlCreateLabel("", 50, 160, 50, 30)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Label4 = GUICtrlCreateLabel("", 50, 220, 50, 30)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlCreateGroup("Group1", 40, 24, 70, 55)
GUICtrlCreateGroup("Group2", 40, 84, 70, 55)
GUICtrlCreateGroup("Group3", 40, 144, 70, 55)
GUICtrlCreateGroup("Group4", 40, 204, 70, 55)
$Button1 = GUICtrlCreateButton("Button1", 176, 56, 75, 25)
GUISetState()
$a = $Label1
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case - 3
Exit
Case $Button1
If $a = $Label4 Then
GUICtrlSetBkColor($a, 0xFFFFFF)
$a = $Label1
GUICtrlSetBkColor($a, 0xffff00)
Else
GUICtrlSetBkColor($a, 0xFFFFFF)
GUICtrlSetBkColor($a + 1, 0xffff00)
$a += 1
EndIf
EndSwitch
WEnd修改了一下,这个应该比上一个聪明点了..... 感谢大家回复!不过我的窗口时要放在FUNC里面的,你们发的这些代码放在FUNC里面不起作用 群里下了你的代码.....
没玩过这个模式的.....等其他人吧=.=
你还是把代码丢上来好一些吧 是这样吗?#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
MyGui()
Func MyGui()
GUICreate("Form1", 300, 400)
$Label1 = GUICtrlCreateLabel("", 50, 40, 50, 30)
GUICtrlSetBkColor(-1, 0xFFFF00)
$Label2 = GUICtrlCreateLabel("", 50, 100, 50, 30)
GUICtrlSetBkColor(-1, 0xFFFF00)
$Label3 = GUICtrlCreateLabel("", 50, 160, 50, 30)
GUICtrlSetBkColor(-1, 0xFFFF00)
$Label4 = GUICtrlCreateLabel("", 50, 220, 50, 30)
GUICtrlSetBkColor(-1, 0xFFFF00)
GUICtrlCreateGroup("Group1", 40, 24, 70, 55)
GUICtrlCreateGroup("Group2", 40, 84, 70, 55)
GUICtrlCreateGroup("Group3", 40, 144, 70, 55)
GUICtrlCreateGroup("Group4", 40, 204, 70, 55)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case - 3
Exit
Case $Label1 To $Label4
Color($nMsg)
EndSwitch
WEnd
EndFunc ;==>MyGui
Func Color($nMsg)
If Eval('!' & $nMsg) = '' Then
GUICtrlSetBkColor($nMsg, 0x00ff00) ;绿色
Assign('!' & $nMsg, 1, 2)
Else
GUICtrlSetBkColor($nMsg, 0xFFFF00) ;黄色
Assign('!' & $nMsg, '', 2)
EndIf
EndFunc ;==>Color 回复 6# guland
那你直接把你的源代理发出来。大家帮你改得了。
页:
[1]