871224 发表于 2009-10-28 16:30:35

点击不同的button创建不同的lable怎么实现

本帖最后由 871224 于 2009-10-28 17:06 编辑


一个界面 有两个按钮 ,1个框框。
点击按钮1,在框框中创建10个lable

$lable_1 = GUICtrlCreateLabel("$lable_1",280,100,50,20)
$lable_2 = GUICtrlCreateLabel("$lable_2",280,120,50,20)
$lable_3 = GUICtrlCreateLabel("$lable_3",280,140,50,20)
.....
$lable_10 = GUICtrlCreateLabel("$lable_1",280,300,50,20)
(创建lable最好用循环)
点击按钮2,框框中变成5个lable。

请问怎么实现。在线等!先谢谢了

netegg 发表于 2009-10-28 16:50:31

发个图看看,没明白你的意思

netegg 发表于 2009-10-28 17:02:01

本帖最后由 netegg 于 2009-10-28 20:12 编辑

明白了
$button1= guictrlcreatebutton()
$button2=guictrlcreatebutton()
local $left = , $top= , $width= , $height = , $space =
For $i = 1 to 10
   $label[$i] = guictrlcreate($i, $LEFT, $Top + ($i - 1) *($space + $height), $width, $heigh)-----》建立标签,用递增变量定义坐标
Guictrlsetstate(-1, $GUI_HIDE)---->所有标签在建立时均为隐藏
   if $i< 6 then Guictrlsetstate(-1, $GUI_SHOW)----->定义需要显示的标签,此处为#1到#5号标签
next
while 1
$msg = GUIGetMsg()---->获取消息
switch $msg
Case $button2 ---->如果消息为button2
    For $i = 6 to 10
    guisetstate($label[$i], $GUI_SHOW)----->显示#6-#10标签
   next
endswitch

871224 发表于 2009-10-28 17:07:11

2# netegg

图已经有了 麻烦看一下

newx 发表于 2009-10-28 17:32:15


#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Local $nLabel ;定义Label数量
$Form1 = GUICreate("Form1", 523, 294, 221, 130)
$Button1 = GUICtrlCreateButton("按钮1", 248, 232, 97, 33)
$Button2 = GUICtrlCreateButton("按钮2", 372, 232, 97, 33)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        CL(10)
                Case $Button2
                        RL(10)
                        CL(5)
        EndSwitch
WEnd

Func CL($Val) ;建立Label(数量)
        For $i=0 to $Val-1
                $nLabel[$i] = GUICtrlCreateLabel("Label"&$i, 40, 32*$i, 36, 17)
        Next
EndFunc

Func RL($Val) ;清除Label(数量)
        For $i=0 to $Val-1
                GUICtrlDelete ( $nLabel[$i] )
        Next
EndFunc

netegg 发表于 2009-10-28 20:04:44

本帖最后由 netegg 于 2009-10-28 20:19 编辑

4# 871224
就按刚才那段,加一部分,没做界面,只是操作
别忘了加个退出部分,我就不写了
$button1= guictrlcreatebutton()
$button2=guictrlcreatebutton()
local $left = , $top= , $width= , $height = , $space =
For $i = 1 to 10
   $label[$i] = guictrlcreate($i, $LEFT, $Top + ($i - 1) *($space + $height), $width, $heigh)-----》建立标签,用递增变量定义坐标
Guictrlsetstate(-1, $GUI_HIDE)---->所有标签在建立时均为隐藏
   if $i< 6 then Guictrlsetstate(-1, $GUI_SHOW)----->定义需要显示的标签,此处为#1到#5号标签
    if not ($i< 6) then Guictrlsetstate(-1, $GUI_HIDE)
next

$msg = GUIGetMsg()---->获取消息
while 1
switch $msg
Case $button1 ---->如果消息为button1
    For $i = 6 to 10
    guisetstate($label[$i], $GUI_SHOW)----->显示#6-#10标签
   next
Case $button2 ---->如果消息为button2
    For $i = 6 to 10
    guisetstate($label[$i], $GUI_HIDE)----->隐藏#6-#10标签
   next
endswitch
wend

netegg 发表于 2009-10-28 20:07:15

5# newx

你这段不是不行,效果类似,不过和楼主的要求似乎不大一样,如果没理解错的话,楼主之所以建两个按钮,是为了选择方便,你那段直接删除了,到最后,如果再要显示,怎么办?重新建?

871224 发表于 2009-10-28 20:36:37

5# newx


谢谢了 ,给了我很大帮助

871224 发表于 2009-10-28 20:37:24

7# netegg


都不错 呵呵 启发很大 删除和隐藏 都可以用用 呵呵 谢谢啦

newx 发表于 2009-10-28 21:45:42

不管是谁的代码,重在参考,只是作个提示,往往一段代码,可以“引伸”其它的领悟

netegg 发表于 2009-10-28 21:47:47

10# newx
同意

871224 发表于 2009-10-28 23:42:48

向大哥们学习!

netegg 发表于 2009-10-28 23:51:14

重在掺和:face (29):
页: [1]
查看完整版本: 点击不同的button创建不同的lable怎么实现