星雨朝霞 发表于 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
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
---------------------------------

3mile 发表于 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
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

看了楼上的代码!再查一下帮助!真想打自己一嘴巴!{:face (258):}

liufenglg 发表于 2010-10-10 17:11:25


3mile 发表于 2010-10-10 10:33 http://www.autoitx.com/images/common/back.gif


    button上怎么没图片显示?

liufenglg 发表于 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
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 我这图标才显示

karlpopper 发表于 2010-10-10 21:50:54

很不错 可惜加了主题的话就无法使用自定义图标 鱼和熊掌难以兼得
页: [1]
查看完整版本: 动态创建按钮如何加上显示图片?