找回密码
 加入
搜索
查看: 2770|回复: 12

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

[复制链接]
发表于 2009-10-28 16:30:35 | 显示全部楼层 |阅读模式
本帖最后由 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。

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

本帖子中包含更多资源

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

×
发表于 2009-10-28 16:50:31 | 显示全部楼层
发个图看看,没明白你的意思
发表于 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
 楼主| 发表于 2009-10-28 17:07:11 | 显示全部楼层
2# netegg

图已经有了 麻烦看一下
发表于 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[10] ;定义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
发表于 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
发表于 2009-10-28 20:07:15 | 显示全部楼层
5# newx

你这段不是不行,效果类似,不过和楼主的要求似乎不大一样,如果没理解错的话,楼主之所以建两个按钮,是为了选择方便,你那段直接删除了,到最后,如果再要显示,怎么办?重新建?
 楼主| 发表于 2009-10-28 20:36:37 | 显示全部楼层
5# newx


谢谢了 ,给了我很大帮助
 楼主| 发表于 2009-10-28 20:37:24 | 显示全部楼层
7# netegg


都不错 呵呵 启发很大 删除和隐藏 都可以用用 呵呵 谢谢啦
发表于 2009-10-28 21:45:42 | 显示全部楼层
不管是谁的代码,重在参考,只是作个提示,往往一段代码,可以“引伸”其它的领悟
发表于 2009-10-28 21:47:47 | 显示全部楼层
10# newx
同意
 楼主| 发表于 2009-10-28 23:42:48 | 显示全部楼层
向大哥们学习!
发表于 2009-10-28 23:51:14 | 显示全部楼层
重在掺和
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-22 17:38 , Processed in 0.077947 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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