找回密码
 加入
搜索
查看: 5283|回复: 8

[效率算法] [已解决]修改控件颜色遇到麻烦,脑子不够用了....

  [复制链接]
发表于 2010-8-14 09:28:04 | 显示全部楼层 |阅读模式
本帖最后由 guland 于 2010-8-14 11:45 编辑



我想做的是点击一下按钮当前控件恢复成原来的颜色,然后下一个控件变成黄色
就想图片中的一样,现在1是黄色,其它的都是白色,点击按钮一次1变成包白色,2变成黄色,以此类推
研究N久没搞明白怎么弄,黄色的部分是Label,那些框是Group,只需要改变Label的背景色就可以了

谢谢大家回复,我的问题没有说清楚,补充一下,我的窗口是要放在func里面的

谢谢大家的解答,最后我用数组加FOR搞定了,代码真实精简一多半啊.........

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-8-14 09:45:58 | 显示全部楼层
帮顶 我不会
发表于 2010-8-14 09:54:34 | 显示全部楼层
本帖最后由 水木子 于 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

评分

参与人数 2金钱 +30 收起 理由
afan + 20
guland + 10 谢谢帮助

查看全部评分

发表于 2010-8-14 10:14:31 | 显示全部楼层
本帖最后由 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[5]
$L[0] = ""
$L[1] =$Label1
$L[2] =$Label2
$L[3] =$Label3
$L[4] =$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
来个笨方法的.....

评分

参与人数 1金钱 +10 收起 理由
guland + 10 谢谢帮助

查看全部评分

发表于 2010-8-14 10:22:22 | 显示全部楼层
#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
修改了一下,这个应该比上一个聪明点了.....

评分

参与人数 2金钱 +30 收起 理由
afan + 20
guland + 10 谢谢帮助

查看全部评分

 楼主| 发表于 2010-8-14 10:37:19 | 显示全部楼层
感谢大家回复!不过我的窗口时要放在FUNC里面的,你们发的这些代码放在FUNC里面不起作用
发表于 2010-8-14 10:45:37 | 显示全部楼层
群里下了你的代码.....
没玩过这个模式的.....等其他人吧=.=
你还是把代码丢上来好一些吧
发表于 2010-8-14 10:54:39 | 显示全部楼层
是这样吗?
#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

评分

参与人数 1金钱 +10 收起 理由
guland + 10 谢谢,刚才我用FOR搞的

查看全部评分

发表于 2010-8-14 11:11:53 | 显示全部楼层
回复 6# guland


    那你直接把你的源代理发出来。大家帮你改得了。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-21 05:09 , Processed in 0.091512 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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