【已解决】如何让文本框中的文本附加方式不跟随光标,而是始终在最后位置插入
本帖最后由 xiehuahere 于 2011-3-10 11:43 编辑直接上代码示例:#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ###
$Form1 = GUICreate("Form1", 252, 327, 192, 124, $WS_CAPTION)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 233, 257, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL))
GUICtrlSetData(-1, "This is the default text.")
$Button1 = GUICtrlCreateButton("Start", 16, 280, 113, 33)
GUICtrlSetOnEvent(-1, "FillEvent")
$Button2 = GUICtrlCreateButton("Exit", 168, 280, 65, 33)
GUICtrlSetOnEvent(-1, "ExitEvent")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
Sleep(10)
WEnd
Func FillEvent()
GUICtrlSetState($Button1, $GUI_DISABLE)
GUICtrlSetState($Button2, $GUI_DISABLE)
GUICtrlSetData($Edit1, "")
$i = 0
While($i < 20)
GUICtrlSetData($Edit1, "TestEdit...", -1)
GUICtrlSetData($Edit1, "Ok" & @CRLF, -1)
$i += 1
Sleep(1000)
WEnd
GUICtrlSetState($Button1, $GUI_ENABLE)
GUICtrlSetState($Button2, $GUI_ENABLE)
EndFunc ;==>ConnectEvent
Func ExitEvent()
Exit 0
EndFunc ;==>ExitEvent在不断往文本框中append内容的过程中,如果鼠标点击改变光标位置,会导致显示混乱。
如何屏蔽光标显示?或者说,如何让append的内容不插入到光标之后而是始终在当前文本的最后插入? 本帖最后由 xiehuahere 于 2011-3-9 13:29 编辑
无表情顶一下。呵呵 请大家帮忙解决,谢谢! 试试UDF
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <GuiConstantsEx.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ###
$Form1 = GUICreate("Form1", 252, 327, 192, 124, $WS_CAPTION)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 233, 257, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL))
GUICtrlSetData(-1, "This is the default text.")
$Button1 = GUICtrlCreateButton("Start", 16, 280, 113, 33)
GUICtrlSetOnEvent(-1, "FillEvent")
$Button2 = GUICtrlCreateButton("Exit", 168, 280, 65, 33)
GUICtrlSetOnEvent(-1, "ExitEvent")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$Debug_Ed = False ; 检查传递给 Edit 函数的类名, 设置为True,并使用另一个控件句柄,看看它的工作.
While 1
Sleep(10)
WEnd
Func FillEvent()
GUICtrlSetState($Button1, $GUI_DISABLE)
GUICtrlSetState($Button2, $GUI_DISABLE)
GUICtrlSetData($Edit1, "")
$i = 0
While($i < 20)
_GUICtrlEdit_AppendText($Edit1, @CRLF & "追加到最后")
;~ GUICtrlSetData($Edit1, "TestEdit...", -1)
;~ GUICtrlSetData($Edit1, "Ok" & @CRLF, -1)
$i += 1
Sleep(1000)
WEnd
GUICtrlSetState($Button1, $GUI_ENABLE)
GUICtrlSetState($Button2, $GUI_ENABLE)
EndFunc ;==>ConnectEvent
Func ExitEvent()
Exit 0
EndFunc ;==>ExitEvent DllCall('user32.dll', 'int', 'DestroyCaret') 4楼的UDF方法,可行!!多谢~~
3mile的 DllCall() 加到while循环里,虽然的确不显示光标了,然而但是,文本附加的位置还是会跟随鼠标点击而变化。
页:
[1]