找回密码
 加入
搜索
查看: 2999|回复: 5

[GUI管理] 【已解决】如何让文本框中的文本附加方式不跟随光标,而是始终在最后位置插入

[复制链接]
发表于 2011-3-5 14:46:10 | 显示全部楼层 |阅读模式
本帖最后由 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的内容不插入到光标之后而是始终在当前文本的最后插入?
 楼主| 发表于 2011-3-5 14:50:49 | 显示全部楼层
本帖最后由 xiehuahere 于 2011-3-9 13:29 编辑

无表情顶一下。呵呵
 楼主| 发表于 2011-3-9 18:17:58 | 显示全部楼层
请大家帮忙解决,谢谢!
发表于 2011-3-9 20:01:55 | 显示全部楼层
试试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

评分

参与人数 1金钱 +15 收起 理由
xiehuahere + 15 谢谢!了解了,要使用UDF~~

查看全部评分

发表于 2011-3-9 22:29:07 | 显示全部楼层
DllCall('user32.dll', 'int', 'DestroyCaret')
 楼主| 发表于 2011-3-10 11:37:25 | 显示全部楼层
4楼的UDF方法,可行!!多谢~~
3mile的 DllCall() 加到while循环里,虽然的确不显示光标了,然而但是,文本附加的位置还是会跟随鼠标点击而变化。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-15 17:34 , Processed in 0.084573 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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