找回密码
 加入
搜索
查看: 3986|回复: 5

[GUI管理] 动态创建按钮如何加上显示图片?

  [复制链接]
发表于 2010-10-10 01:27:48 | 显示全部楼层 |阅读模式
在论坛某处找到这个代码:
#include <GuiConstants.au3>
Opt("GUIOnEventMode", 1)
 
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 494, 345, 192, 114)
GUISetOnEvent($GUI_EVENT_CLOSE, "main")
Dim $Button[3]
GUISetState()
#EndRegion ### END Koda GUI section ###
For $i = 0 To 2
        $Button[$i] = GUICtrlCreateButton("Button" & $i, 320, 64+30*($i), 121, 25,0)
        GUICtrlSetOnEvent($Button[$i], "main")
Next
 
While 1
        Sleep(1000)
WEnd
 
Func main()
        For $i = 0 To 2
                Switch @GUI_CtrlId
                        Case $GUI_EVENT_CLOSE
                                Exit
                        Case $Button[$i]
                                MsgBox(0, "", "button" & $i)
                EndSwitch
        Next
EndFunc   ;==>main
这个可以动态创建按钮!我想改成按钮可以显示图片的!
我在以上代码基础上按钮加上样式$BS_BITMAP,运行后就杯具了!!出错!
F:\?????\????\360????\?? AutoIt v3 ??.au3 (11) : ==> ?????????.:
$Button[$i] = GUICtrlCreateButton("Button" & $i, 320, 64+30*($i), 121, 25,$BS_BITMAP)
$Button[$i] = GUICtrlCreateButton("Button" & $i, 320, 64+30*($i), 121, 25,^ ERROR
---------------------------------
发表于 2010-10-10 10:33:21 | 显示全部楼层
#include <GuiConstants.au3>
#include <ButtonConstants.au3>

Opt("GUIOnEventMode", 1)
 
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 494, 345, 192, 114)
GUISetOnEvent($GUI_EVENT_CLOSE, "main")
Dim $Button[3]
GUISetState()
#EndRegion ### END Koda GUI section ###
For $i = 0 To 2
        $Button[$i] = GUICtrlCreateButton("Button" & $i, 320, 64+30*($i), 121, 25,0,$BS_BITMAP)
        GUICtrlSetImage(-1,'shell32.dll',Random(27,40,1))
        GUICtrlSetOnEvent($Button[$i], "main")
Next
 
While 1
        Sleep(1000)
WEnd
 
Func main()
        For $i = 0 To 2
                Switch @GUI_CtrlId
                        Case $GUI_EVENT_CLOSE
                                Exit
                        Case $Button[$i]
                                MsgBox(0, "", "button" & $i)
                EndSwitch
        Next
EndFunc   ;==>main
 楼主| 发表于 2010-10-10 16:36:07 | 显示全部楼层
看了楼上的代码!再查一下帮助!真想打自己一嘴巴!
发表于 2010-10-10 17:11:25 | 显示全部楼层
3mile 发表于 2010-10-10 10:33



    button上怎么没图片显示?
发表于 2010-10-10 17:23:40 | 显示全部楼层
#include <GuiConstants.au3>
#include <ButtonConstants.au3>

Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 500, 400, 192, 114)
GUISetOnEvent($GUI_EVENT_CLOSE, "main")
Dim $Button[3]
GUISetState()
#EndRegion ### END Koda GUI section ###
For $i = 0 To 2
        $Button[$i] = GUICtrlCreateButton("Button" & $i, 320, 64+30*($i), 121, 25,$BS_icon )
        GUICtrlSetImage(-1,"shell32.dll",Random(1,25,1))
        GUICtrlSetOnEvent($Button[$i], "main")
Next

While 1
        Sleep(1000)
WEnd

Func main()
        For $i = 0 To 2
                Switch @GUI_CtrlId
                        Case $GUI_EVENT_CLOSE
                                Exit
                        Case $Button[$i]
                                MsgBox(0, "", "button" & $i)
                EndSwitch
        Next
EndFunc   ;==>main


把$BS_BITMAP 改为$BS_ICON 我这图标才显示
发表于 2010-10-10 21:50:54 | 显示全部楼层
很不错 可惜加了主题的话就无法使用自定义图标 鱼和熊掌难以兼得
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-20 22:52 , Processed in 0.077767 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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