我正在学习AutoIT和我试图写一个脚本的GUI,让我们用户输入一些值,点击OK按钮,然后看到相同的值在按下另一个OK按钮之前再次显示,退出脚本。
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
Example()
Func Example()
Local $file, $btn, $msg
Local $width1, $width2, $iOldOpt
local $startangle, $endangle, $nomeas, $time
GUICreate("My GUI",370,160) ; will create a dialog box that when displayed is centered
$iOldOpt = Opt("GUICoordMode", 2)
$width1 = 300
$width2 = 50
GUICtrlCreateLabel("Startvinkel i förhållande till referensriktningen (grader):", 10, 30, $width1)
$startangle = GUICtrlCreateInput("", 0, -1, $width2)
GUICtrlCreateLabel("Slutvinkel i förhållande till referensriktningen (grader):", -($width1+$width2), 0, $width1)
$endangle = GUICtrlCreateInput("", 0, -1, $width2)
GUICtrlCreateLabel("Antal mätriktningar:", -($width1+$width2), 0, $width1)
$nomeas = GUICtrlCreateInput("", 0, -1, $width2)
GUICtrlCreateLabel("Mättid i varje riktning (sekunder):", -($width1+$width2), 0, $width1)
$time = GUICtrlCreateInput("", 0, -1, $width2)
$iOldOpt = Opt("GUICoordMode", 1)
$btn = GUICtrlCreateButton("Ok", 155, 130, 60, 20)
GUISetState(@SW_SHOW)
$msg = 0
; Loop until the user exits.
While $msg <> $GUI_EVENT_CLOSE
$msg = GUIGetMsg()
Select
Case $msg = $btn
ExitLoop
EndSelect
WEnd
GUICreate("My GUI",370,160) ; will create a dialog box that when displayed is centered
$iOldOpt = Opt("GUICoordMode", 2)
GUICtrlCreateLabel("Startvinkel i förhållande till referensriktningen (grader):", 10, 30, $width1)
GUICtrlCreateLabel(GUICtrlRead($startangle), 0, -1, $width2)
GUICtrlCreateLabel("Slutvinkel i förhållande till referensriktningen (grader):", -($width1+$width2), 0, $width1)
GUICtrlCreateLabel(GUICtrlRead($endangle), 0, -1, $width2)
GUICtrlCreateLabel("Antal mätriktningar:", -($width1+$width2), 0, $width1)
GUICtrlCreateLabel(GUICtrlRead($nomeas), 0, -1, $width2)
GUICtrlCreateLabel("Mättid i varje riktning (sekunder):", -($width1+$width2), 0, $width1)
GUICtrlCreateLabel(GUICtrlRead($time), 0, -1, $width2)
$iOldOpt = Opt("GUICoordMode", 1)
$btn = GUICtrlCreateButton("Ok", 155, 130, 60, 20)
While $msg <> $GUI_EVENT_CLOSE
$msg = GUIGetMsg()
Select
Case $msg = $btn
ExitLoop
EndSelect
WEnd
MsgBox($MB_SYSTEMMODAL, "Finished", GUICtrlRead($nomeas))
EndFunc
脚本启动,显示第一个GUI,让我输入我的值,但是当我单击OK按钮时,什么也没有发生。为什么会这样?
这个脚本在某种程度上是基于一个编码示例,其中单击OK按钮会将您带到一个"消息框",如脚本的后半部分所示。我所做的基本上是删除MsgBox()行,并用guiccreate()代替它。
像这样?
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
Example()
Func Example()
Local $file, $btn, $msg
Local $width1, $width2, $iOldOpt
Local $startangle, $endangle, $nomeas, $time
GUICreate("My GUI", 570, 260) ; will create a dialog box that when displayed is centered
$iOldOpt = Opt("GUICoordMode", 2)
$width1 = 300
$width2 = 50
GUICtrlCreateLabel("Startvinkel i förhållande till referensriktningen (grader):", 10, 30, $width1)
$startangle = GUICtrlCreateInput("", 0, -1, $width2)
GUICtrlCreateLabel("Slutvinkel i förhållande till referensriktningen (grader):", -($width1 + $width2), 0, $width1)
$endangle = GUICtrlCreateInput("", 0, -1, $width2)
GUICtrlCreateLabel("Antal mätriktningar:", -($width1 + $width2), 0, $width1)
$nomeas = GUICtrlCreateInput("", 0, -1, $width2)
GUICtrlCreateLabel("Mättid i varje riktning (sekunder):", -($width1 + $width2), 0, $width1)
$time = GUICtrlCreateInput("", 0, -1, $width2)
$iOldOpt = Opt("GUICoordMode", 1)
$btn = GUICtrlCreateButton("Ok", 155, 130, 60, 20)
$1 = GUICtrlCreateLabel("Startvinkel i förhållande till referensriktningen (grader):", 10, 160, 500, 20)
$2 = GUICtrlCreateLabel("Slutvinkel i förhållande till referensriktningen (grader):", 10, 180, 500, 20)
$3 = GUICtrlCreateLabel("Antal mätriktningar:", 10, 200, 500, 20)
$4 = GUICtrlCreateLabel("Mättid i varje riktning (sekunder):", 10, 220, 500, 20)
GUISetState(@SW_SHOW)
$msg = 0
; Loop until the user exits.
While $msg <> $GUI_EVENT_CLOSE
$msg = GUIGetMsg()
Select
Case $msg = $btn
;~ MsgBox($MB_SYSTEMMODAL, "Finished", 'Antal mätriktningar: ' & GUICtrlRead($nomeas))
GUICtrlSetData($1, GUICtrlRead($1) & ', ' & GUICtrlRead($nomeas))
GUICtrlSetData($2, GUICtrlRead($2) & ', ' & GUICtrlRead($endangle))
GUICtrlSetData($3, GUICtrlRead($3) & ', ' & GUICtrlRead($time))
GUICtrlSetData($4, GUICtrlRead($4) & ', ' & GUICtrlRead($startangle))
GUICtrlSetData($nomeas, '')
GUICtrlSetData($endangle, '')
GUICtrlSetData($time, '')
GUICtrlSetData($startangle, '')
EndSelect
WEnd
EndFunc ;==>Example
我猜你想要这个
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
Example()
Func Example()
Local $file, $btn, $msg
Local $width1, $width2, $iOldOpt
Local $startangle, $endangle, $nomeas, $time
GUICreate("My GUI", 370, 160) ; will create a dialog box that when displayed is centered
$iOldOpt = Opt("GUICoordMode", 2)
$width1 = 300
$width2 = 50
GUICtrlCreateLabel("Startvinkel i förhållande till referensriktningen (grader):", 10, 30, $width1)
$startangle = GUICtrlCreateInput("", 0, -1, $width2)
GUICtrlCreateLabel("Slutvinkel i förhållande till referensriktningen (grader):", -($width1 + $width2), 0, $width1)
$endangle = GUICtrlCreateInput("", 0, -1, $width2)
GUICtrlCreateLabel("Antal mätriktningar:", -($width1 + $width2), 0, $width1)
$nomeas = GUICtrlCreateInput("", 0, -1, $width2)
GUICtrlCreateLabel("Mättid i varje riktning (sekunder):", -($width1 + $width2), 0, $width1)
$time = GUICtrlCreateInput("", 0, -1, $width2)
$iOldOpt = Opt("GUICoordMode", 1)
$btn = GUICtrlCreateButton("Ok", 155, 130, 60, 20)
GUISetState(@SW_SHOW)
$msg = 0
; Loop until the user exits.
While $msg <> $GUI_EVENT_CLOSE
$msg = GUIGetMsg()
Select
Case $msg = $btn
MsgBox($MB_SYSTEMMODAL, "Finished", 'Antal mätriktningar: ' & GUICtrlRead($nomeas))
GUICtrlSetData($nomeas, '')
GUICtrlSetData($endangle, '')
GUICtrlSetData($time, '')
GUICtrlSetData($startangle, '')
EndSelect
WEnd
EndFunc ;==>Example