发一个AU3的活动表格(试验品)
本帖最后由 dnbj2010 于 2011-11-27 22:54 编辑发一个AU3的活动表格
奇怪,RAR附件发不上,看不到上传选择,网络问题?
汗死!这垃圾网络... 沙发上有人等待楼主上传呢!{:face (303):} 不易啊,终于传上了。
截图:
看看啦!!!! 咦,这个不错,看看,哈哈哈,谢谢楼主分享.. 没有源码的哈。。 上源码:#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
Opt("GUIOnEventMode", 1)
Local $Edit,$Hount=3,$WCount=3,$Ctr,$j=0
$Form1 = GUICreate("Form1", 700, 444, 150, 120)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
For $b = 1 to $Hount
For $a = 1 to $WCount
$j = $j + 1
$Edit[$a][$b] =GUICtrlCreateEdit($j, 130+($a-1)*170, 66+($b-1)*90, 170, 90, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN))
Next
Next
$Label1 = GUICtrlCreateLabel("把鼠标移到边线 按下左键 可以调整单元格的大小", 200, 10, 300, 17)
GUISetState(@SW_SHOW)
While 1
Sleep(1)
$GUICur = GUIGetCursorInfo($Form1)
If $GUICur = 1 Then
lashen()
EndIf
WEnd
Func lashen()
$k = 1
$Ctr1 = ControlGetPos("Form1","",$Edit) ;控件信息
$Ctr2 = ControlGetPos("Form1","",$Edit)
$Ctr3 = ControlGetPos("Form1","",$Edit)
$Ctr4 = ControlGetPos("Form1","",$Edit)
$Ctr5 = ControlGetPos("Form1","",$Edit)
$Ctr6 = ControlGetPos("Form1","",$Edit)
$Ctr7 = ControlGetPos("Form1","",$Edit)
$Ctr8 = ControlGetPos("Form1","",$Edit)
$Ctr9 = ControlGetPos("Form1","",$Edit)
$nPos = WinGetPos("Form1") ;主窗信息
;-------------------------------------------------------------------------------右边
$La1x1 = ($GUICur > $Ctr1 + $Ctr1- 8)
$La1x2 = ($GUICur < $Ctr1 + $Ctr1)
$La2x1 = ($GUICur > $Ctr2 + $Ctr2- 8)
$La2x2 = ($GUICur < $Ctr2 + $Ctr2)
$La3x1 = ($GUICur > $Ctr3 + $Ctr3- 8)
$La3x2 = ($GUICur < $Ctr3 + $Ctr3)
;--------------------------------------------------------------------------------左边
$Ra1x1 = ($GUICur < $Ctr1+ 8)
$Ra1x2 = ($GUICur > $Ctr1)
$Ra2x1 = ($GUICur < $Ctr2+ 8)
$Ra2x2 = ($GUICur > $Ctr2)
$Ra3x1 = ($GUICur < $Ctr3+ 8)
$Ra3x2 = ($GUICur > $Ctr3)
;------------------------------------------------------------------------------ 上边
$Ta1y1 = ($GUICur < $Ctr1+ 8)
$Ta1y2 = ($GUICur > $Ctr1)
$Ta4y1 = ($GUICur < $Ctr4+ 8)
$Ta4y2 = ($GUICur > $Ctr4)
$Ta7y1 = ($GUICur < $Ctr7+ 8)
$Ta7y2 = ($GUICur > $Ctr7)
;------------------------------------------------------------------------------下边
$Ea1y1 = ($GUICur > $Ctr1 + $Ctr1- 8)
$Ea1y2 = ($GUICur < $Ctr1 + $Ctr1)
$Ea4y1 = ($GUICur > $Ctr4 + $Ctr4- 8)
$Ea4y2 = ($GUICur < $Ctr4 + $Ctr4)
$Ea7y1 = ($GUICur > $Ctr7 + $Ctr7- 8)
$Ea7y2 = ($GUICur < $Ctr7 + $Ctr7)
;------------------------------------------------------------------------------
If $La1x1 And $La1x2 Then
If $k = 1 Then
ControlMove ("Form1","", $Edit,$Ctr1,$Ctr1,$GUICur+4-$Ctr1,$Ctr1)
ControlMove ("Form1","", $Edit,$Ctr4,$Ctr4,$GUICur+4-$Ctr4,$Ctr4)
ControlMove ("Form1","", $Edit,$Ctr7,$Ctr7,$GUICur+4-$Ctr7,$Ctr7)
ControlMove ("Form1","", $Edit,$GUICur+8-4,$Ctr2,$Ctr2-($GUICur+8-4-$Ctr2),$Ctr2)
ControlMove ("Form1","", $Edit,$GUICur+8-4,$Ctr5,$Ctr5-($GUICur+8-4-$Ctr5),$Ctr5)
ControlMove ("Form1","", $Edit,$GUICur+8-4,$Ctr8,$Ctr8-($GUICur+8-4-$Ctr8),$Ctr8)
EndIf
EndIf
If $Ra1x1 And $Ra1x2 Then
If $k = 1 Then
ControlMove ("Form1","", $Edit,$GUICur-4,$Ctr1,$Ctr1-($GUICur-4-$Ctr1),$Ctr1)
ControlMove ("Form1","", $Edit,$GUICur-4,$Ctr4,$Ctr4-($GUICur-4-$Ctr4),$Ctr4)
ControlMove ("Form1","", $Edit,$GUICur-4,$Ctr7,$Ctr7-($GUICur-4-$Ctr7),$Ctr7)
EndIf
EndIf
If $Ta1y1 And $Ta1y2 Then
If $k = 1 Then
ControlMove ("Form1","", $Edit,$Ctr1,$GUICur-4,$Ctr1,$Ctr1-($GUICur-4-$Ctr1))
ControlMove ("Form1","", $Edit,$Ctr2,$GUICur-4,$Ctr2,$Ctr2-($GUICur-4-$Ctr2))
ControlMove ("Form1","", $Edit,$Ctr3,$GUICur-4,$Ctr3,$Ctr3-($GUICur-4-$Ctr3))
EndIf
EndIf
If $Ea1y1 And $Ea1y2 Then
If $k = 1 Then
ControlMove ("Form1","", $Edit,$Ctr1,$Ctr1,$Ctr1,$GUICur+4-$Ctr1)
ControlMove ("Form1","", $Edit,$Ctr2,$Ctr2,$Ctr2,$GUICur+4-$Ctr2)
ControlMove ("Form1","", $Edit,$Ctr3,$Ctr3,$Ctr3,$GUICur+4-$Ctr3)
ControlMove ("Form1","", $Edit,$Ctr4,$GUICur+8-4,$Ctr4,$Ctr4-($GUICur+8-4-$Ctr4))
ControlMove ("Form1","", $Edit,$Ctr5,$GUICur+8-4,$Ctr5,$Ctr5-($GUICur+8-4-$Ctr5))
ControlMove ("Form1","", $Edit,$Ctr6,$GUICur+8-4,$Ctr6,$Ctr6-($GUICur+8-4-$Ctr6))
EndIf
EndIf
If $Ra2x1 And $Ra2x2 Then
If $k = 1 Then
ControlMove ("Form1","", $Edit,$Ctr1,$Ctr1,$GUICur-8+4-$Ctr1,$Ctr1)
ControlMove ("Form1","", $Edit,$GUICur-4,$Ctr2,$Ctr2-($GUICur-4-$Ctr2),$Ctr2)
ControlMove ("Form1","", $Edit,$Ctr4,$Ctr4,$GUICur-8+4-$Ctr4,$Ctr4)
ControlMove ("Form1","", $Edit,$Ctr7,$Ctr7,$GUICur-8+4-$Ctr7,$Ctr7)
ControlMove ("Form1","", $Edit,$GUICur-4,$Ctr5,$Ctr5-($GUICur-4-$Ctr5),$Ctr5)
ControlMove ("Form1","", $Edit,$GUICur-4,$Ctr8,$Ctr8-($GUICur-4-$Ctr8),$Ctr8)
EndIf
EndIf
If $La2x1 And $La2x2 Then
If $k = 1 Then
ControlMove ("Form1","", $Edit,$Ctr2,$Ctr2,$GUICur+4-$Ctr2,$Ctr2)
ControlMove ("Form1","", $Edit,$Ctr5,$Ctr5,$GUICur+4-$Ctr5,$Ctr5)
ControlMove ("Form1","", $Edit,$Ctr8,$Ctr8,$GUICur+4-$Ctr8,$Ctr8)
ControlMove ("Form1","", $Edit,$GUICur+8-4,$Ctr3,$Ctr3-($GUICur+8-4-$Ctr3),$Ctr3)
ControlMove ("Form1","", $Edit,$GUICur+8-4,$Ctr6,$Ctr6-($GUICur+8-4-$Ctr6),$Ctr6)
ControlMove ("Form1","", $Edit,$GUICur+8-4,$Ctr9,$Ctr9-($GUICur+8-4-$Ctr9),$Ctr9)
EndIf
EndIf
If $Ra3x1 And $Ra3x2 Then
If $k = 1 Then
ControlMove ("Form1","", $Edit,$Ctr2,$Ctr2,$GUICur-8+4-$Ctr2,$Ctr2)
ControlMove ("Form1","", $Edit,$GUICur-4,$Ctr3,$Ctr3-($GUICur-4-$Ctr3),$Ctr3)
ControlMove ("Form1","", $Edit,$Ctr5,$Ctr5,$GUICur-8+4-$Ctr5,$Ctr5)
ControlMove ("Form1","", $Edit,$Ctr8,$Ctr8,$GUICur-8+4-$Ctr8,$Ctr8)
ControlMove ("Form1","", $Edit,$GUICur-4,$Ctr6,$Ctr6-($GUICur-4-$Ctr6),$Ctr6)
ControlMove ("Form1","", $Edit,$GUICur-4,$Ctr9,$Ctr9-($GUICur-4-$Ctr9),$Ctr9)
EndIf
EndIf
If $La3x1 And $La3x2 Then
If $k = 1 Then
ControlMove ("Form1","", $Edit,$Ctr3,$Ctr3,$GUICur+4-$Ctr3,$Ctr3)
ControlMove ("Form1","", $Edit,$Ctr6,$Ctr6,$GUICur+4-$Ctr6,$Ctr6)
ControlMove ("Form1","", $Edit,$Ctr9,$Ctr9,$GUICur+4-$Ctr9,$Ctr9)
EndIf
EndIf
If $Ta4y1 And $Ta4y2 Then
If $k = 1 Then
ControlMove ("Form1","", $Edit,$Ctr1,$Ctr1,$Ctr1,$GUICur-8+4-$Ctr1)
ControlMove ("Form1","", $Edit,$Ctr2,$Ctr2,$Ctr2,$GUICur-8+4-$Ctr2)
ControlMove ("Form1","", $Edit,$Ctr3,$Ctr3,$Ctr3,$GUICur-8+4-$Ctr3)
ControlMove ("Form1","", $Edit,$Ctr4,$GUICur-4,$Ctr4,$Ctr4-($GUICur-4-$Ctr4))
ControlMove ("Form1","", $Edit,$Ctr5,$GUICur-4,$Ctr5,$Ctr5-($GUICur-4-$Ctr5))
ControlMove ("Form1","", $Edit,$Ctr6,$GUICur-4,$Ctr6,$Ctr6-($GUICur-4-$Ctr6))
EndIf
EndIf
If $Ea4y1 And $Ea4y2 Then
If $k = 1 Then
ControlMove ("Form1","", $Edit,$Ctr4,$Ctr4,$Ctr4,$GUICur+4-$Ctr4)
ControlMove ("Form1","", $Edit,$Ctr5,$Ctr5,$Ctr5,$GUICur+4-$Ctr5)
ControlMove ("Form1","", $Edit,$Ctr6,$Ctr6,$Ctr6,$GUICur+4-$Ctr6)
ControlMove ("Form1","", $Edit,$Ctr7,$GUICur+8-4,$Ctr7,$Ctr7-($GUICur+8-4-$Ctr7))
ControlMove ("Form1","", $Edit,$Ctr8,$GUICur+8-4,$Ctr8,$Ctr8-($GUICur+8-4-$Ctr8))
ControlMove ("Form1","", $Edit,$Ctr9,$GUICur+8-4,$Ctr9,$Ctr9-($GUICur+8-4-$Ctr9))
EndIf
EndIf
If $Ta7y1 And $Ta7y2 Then
If $k = 1 Then
ControlMove ("Form1","", $Edit,$Ctr4,$Ctr4,$Ctr4,$GUICur-8+4-$Ctr4)
ControlMove ("Form1","", $Edit,$Ctr5,$Ctr5,$Ctr5,$GUICur-8+4-$Ctr5)
ControlMove ("Form1","", $Edit,$Ctr6,$Ctr6,$Ctr6,$GUICur-8+4-$Ctr6)
ControlMove ("Form1","", $Edit,$Ctr7,$GUICur-4,$Ctr7,$Ctr7-($GUICur-4-$Ctr7))
ControlMove ("Form1","", $Edit,$Ctr8,$GUICur-4,$Ctr8,$Ctr8-($GUICur-4-$Ctr8))
ControlMove ("Form1","", $Edit,$Ctr9,$GUICur-4,$Ctr9,$Ctr9-($GUICur-4-$Ctr9))
EndIf
EndIf
If $Ea7y1 And $Ea7y2 Then
If $k = 1 Then
ControlMove ("Form1","", $Edit,$Ctr7,$Ctr7,$Ctr7,$GUICur+4-$Ctr7)
ControlMove ("Form1","", $Edit,$Ctr8,$Ctr8,$Ctr8,$GUICur+4-$Ctr8)
ControlMove ("Form1","", $Edit,$Ctr9,$Ctr9,$Ctr9,$GUICur+4-$Ctr9)
EndIf
EndIf
EndFunc
Func CLOSEClicked()
GUIDelete($Form1)
Exit
EndFunc
上面的代码还可以用数组精简一下。
这里有问题还要请教一下高手,
如下:
$Ctr1 = ControlGetPos("Form1","",$Edit)
$Ctr1返回的是一个数组,这对于指明的单个控件没问题
但下面这种:
$Ctr1 = ControlGetPos("Form1","",$Edit)
$Ctr2 = ControlGetPos("Form1","",$Edit)
$Ctr3 = ControlGetPos("Form1","",$Edit)
......................................
.....................................
是动态生成的 $Ctr1,$Ctr2,$Ctr3,$Ctr4,$Ctr5......
尝试用:$Ctr[$i],或者$Ctr[$i][$h] 这种方式来表达,行不通
因为: $Ctr[$i] = ControlGetPos("Form1","",$Edit[$i]) 这种表达式 AU3显示错误
这种情况应如何表达?
这种情况应如何表达?
这种情况应如何表达?
.......
....... 记得有人说过好像用eval吧 回复 10# zxxputian
变量名:$ad1,$ad2,$ad3
用eval 的等效值变量:
$ad1 = eval("ad1")
1 2 3 可以变动,那就可以这样写
eval("ad"&$i) 这里的$i 就是你的1 2 3自己去for
==================================================
GUICtrlRead($adv)= GUICtrlRead(eval("adv")) 本帖最后由 dnbj2010 于 2011-11-28 17:21 编辑
回复 11# 绿色风
-----------------------------------------
谢谢回复,又多了解了一种变量表达式的写法。
但这个Eval ( 表达式 )还是不能解决对 ControlGetPos的动态变量的定义。
看来只好换种求控件坐标的方法了。
如下:Eval("Ctr"& $i)只能在ControlGetPos已经被定义的情况下才能有效,不能取代 $Ctr1 =...这一段#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Local $i = 1
$Form1 = GUICreate("Form1", 700, 444, 150, 120)
$Button1 = GUICtrlCreateButton("Button1", 248, 88, 75, 25)
$Ctr1 = ControlGetPos("Form1","",$Button1)
MsgBox(0,"",Eval("Form"& $i))
MsgBox(0,"",Eval("Button"& $i))
MsgBox(0,"",Eval("Ctr"& $i))
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd 谢谢分享!
但下次发源码东西请发到源码区!
发无源码的成品请发作品展览区! 谢谢分享!
但下次发源码东西请发到源码区!
发无源码的成品请发作品展览区!
user3000 发表于 2011-11-28 16:57 http://www.autoitx.com/images/common/back.gif
------------------------------------------
谢提醒,那这次麻烦版主把贴子挪到源码作品区吧。 本帖最后由 绿色风 于 2011-11-29 03:44 编辑
回复 14# dnbj2010
不知你是不是要这样的。
用 eval 的大哥 Assign 去做。
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Dim $button5
$Form1 = GUICreate("Form1", 700, 444, 150, 120)
For $i = 0 To 6
Assign("Button"&$i , GUICtrlCreateButton("按钮 - "&$i, 148, 18+$i * 30, 75, 25))
Next
$test1 = GUICtrlCreateButton("点我 ", 248, 50, 75, 25)
$test2 = GUICtrlCreateButton("直接显示 按钮5 ", 248, 80, 175, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $test1
For $i = 0 To 6
MsgBox(0,"",GUICtrlRead(Eval("button"&$i)))
Next
Case $test2
MsgBox(0,"",GUICtrlRead($button5)) ;这样写时,$button5需要事先声明
EndSwitch
WEnd
解决你的
$Ctr1 = ControlGetPos("Form1","",$Edit)
$Ctr2 = ControlGetPos("Form1","",$Edit)
$Ctr3 = ControlGetPos("Form1","",$Edit)
应该没问题吧
For $i = 1 To 3
Assign("ctr"&$i,ControlGetPos("Form1","",$Edit[$i])
Next