3

我正在开发一个 AutoIt GUI,只是我自己的一个小示例框,我想知道如何将另一行文本添加到编辑框..

目前,(当我按下“按钮 1”时)编辑框显示:

'Button 1 was pressed'   

但是当您按下另一个按钮时会重置。在不删除编辑框中已有的文本的情况下,我应该如何添加新的文本行?-提前致谢。

Opt("GUIOnEventMode", 1)  
$Form2 = GUICreate("line trial", 552, 178, 192, 124)  
GUISetOnEvent($GUI_EVENT_CLOSE, "Form2Close")  
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form2Minimize")  
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form2Maximize")  
GUISetOnEvent($GUI_EVENT_RESTORE, "Form2Restore")  
$editbox = GUICtrlCreateEdit("", 8, 8, 409, 169)  
GUICtrlSetData(-1, "editbox")  
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT)  
GUICtrlSetOnEvent(-1, "editboxChange")  
$Group1 = GUICtrlCreateGroup("Options", 424, 0, 121, 137)  
$Button1 = GUICtrlCreateButton("Button1", 432, 16, 51, 17)  
GUICtrlSetOnEvent(-1, "Button1Click")  
$Button2 = GUICtrlCreateButton("Button2", 432, 40, 51, 17)  
GUICtrlSetOnEvent(-1, "Button2Click")  
$Button3 = GUICtrlCreateButton("Button3", 432, 64, 51, 17)  
GUICtrlSetOnEvent(-1, "Button3Click")  
$Button4 = GUICtrlCreateButton("Button4", 432, 88, 51, 17)  
GUICtrlSetOnEvent(-1, "Button4Click")  
$Button5 = GUICtrlCreateButton("Button5", 432, 112, 51, 17)  
GUICtrlSetOnEvent(-1, "Button5Click")  
$Button6 = GUICtrlCreateButton("Button6", 488, 16, 51, 17)  
GUICtrlSetOnEvent(-1, "Button6Click")  
$Button7 = GUICtrlCreateButton("Button7", 488, 40, 51, 17)  
GUICtrlSetOnEvent(-1, "Button7Click")  
$Button8 = GUICtrlCreateButton("Button8", 488, 64, 51, 17)  
GUICtrlSetOnEvent(-1, "Button8Click")  
$Button9 = GUICtrlCreateButton("Button9", 488, 88, 51, 17)  
GUICtrlSetOnEvent(-1, "Button9Click")  
$Button10 = GUICtrlCreateButton("Button10", 488, 112, 51, 17)  
GUICtrlSetOnEvent(-1, "Button10Click")  
GUICtrlCreateGroup("", -99, -99, 1, 1)  
$Button11 = GUICtrlCreateButton("Exit", 424, 144, 59, 25)  
GUICtrlSetOnEvent(-1, "Button11Click")  
$Button12 = GUICtrlCreateButton("Clear", 496, 144, 51, 25)  
GUICtrlSetOnEvent(-1, "Button12Click")  
GUISetState(@SW_SHOW)  
Global $File1 = "test.txt"  


While 1  
    Sleep(100)  
WEnd  

Func Button10Click()  
GUICtrlSetData($editbox, "Button 10 was pressed  ")  
FileWriteLine($File1, "Button 10 was pressed")  
EndFunc  


Func Button11Click()  
If FileExists("test.txt") Then  
      FileDelete ( "test.txt" )  
      exit  
Else    
  exit  
EndIf  
EndFunc  


Func Button12Click()  
GUICtrlSetData($editbox, "")  
EndFunc  


Func Button1Click()  
 GUICtrlSetData($editbox, "Button 1 was pressed")  
FileWriteLine($File1, "Button 1 was pressed")  
EndFunc  


Func Button2Click()  
 GUICtrlSetData($editbox, "Button 2 was pressed  ")  
 FileWriteLine($File1, "Button 2 was pressed")  
EndFunc  


Func Button3Click()  
 GUICtrlSetData($editbox, "Button 3 was pressed  ")  
 FileWriteLine($File1, "Button 3 was pressed")  
EndFunc  


Func Button4Click()  
 GUICtrlSetData($editbox, "Button 4 was pressed  ")  
 FileWriteLine($File1, "Button 4 was pressed")  
EndFunc  


Func Button5Click()  
 GUICtrlSetData($editbox, "Button 5 was pressed  ")  
 FileWriteLine($File1, "Button 5 was pressed")  
EndFunc  


Func Button6Click()  
 GUICtrlSetData($editbox, "Button 6 was pressed  ")  
 FileWriteLine($File1, "Button 6 was pressed")  
EndFunc  


Func Button7Click()  
 GUICtrlSetData($editbox, "Button 7 was pressed  ", 1)  
 FileWriteLine($File1, "Button 7 was pressed")  
EndFunc  


Func Button8Click()  
 GUICtrlSetData($editbox, "Button 8 was pressed  ")  
 FileWriteLine($File1, "Button 8 was pressed")  
EndFunc  


Func Button9Click()  
 GUICtrlSetData($editbox, "Button 9 was pressed    
 FileWriteLine($File1, "Button 9 was pressed")  
EndFunc  


Func editboxChange() 
 Global $editline1 = GUICtrlRead($editbox)   
 GUICtrlSetData($editbox, $editline1)     
EndFunc  


Func Form2Close()  
exit
EndFunc  
4

3 回答 3

3

更改这些功能行:

GUICtrlSetData($editbox, "Button 10 was pressed  ")  

到:

GUICtrlSetData($editbox, "Button 10 was pressed" & @CRLF, 1)  
于 2013-10-05T20:08:18.463 回答
1

或者您可以查看:_GUICtrlEdit_AppendText():

#include <GuiEdit.au3>
_GUICtrlEdit_AppendText($editbox, @CRLF & "Button 10 was pressed")
于 2015-01-04T07:09:36.617 回答
0

我遵循了上述建议,即 ...,1) 表示插入,而不是替换。

但是,在测试中,它仍然可以替换。

我发现如果初始 GUICtrlSetData 在 GUISetState() 之前,则该字段被突出显示,第二行替换它。

; THIS IS WRONG (First Line overlaid by second)
GUICreate("My GUI edit")
$myedit=GUICtrlCreateEdit("First Line" & @CRLF, 30,32,200,97,$ES_AUTOVSCROLL+$WS_VSCROLL)
GUISetState()
GUICtrlSetData($myedit, "Second line" & @CRLF,1)

;THIS IS RIGHT
GUICreate("My GUI edit")
GUISetState()
$myedit=GUICtrlCreateEdit("First Line" & @CRLF, 30,32,200,97,$ES_AUTOVSCROLL+$WS_VSCROLL)
GUICtrlSetData($myedit, "Second line" & @CRLF,1)

如果在 GuiSetState 之前创建一个带有初始值的编辑框,它似乎是“脆弱的”,即会显示出来,但会突出显示,随后的 GuiCtrlSetData() 将覆盖它,即使以“,1)”​​结尾

于 2015-01-03T22:37:43.333 回答