找回密码
 加入
搜索
查看: 3094|回复: 18

edit输入框被用户干挠的疑问

  [复制链接]
发表于 2009-12-31 16:32:36 | 显示全部楼层 |阅读模式
本帖最后由 itljl 于 2010-1-1 00:09 编辑



如图,当程序自动往edit框添数据时,当用户点击了输入框某个位置时,程序添的数据就会从点击的地方开始。而不是从最下面。
GUICtrlSetData($Edit1,"这是行 " & $i & @crlf,"1")
这样就是往最下添数据

现在发现有一种方法不受用户干挠会自动添加数据到最下面,
那就是禁用控件,;~ GUICtrlSetState (-1, $GUI_DISABLE )  ,但控制将变成灰色,字就看不清楚了。

有兄弟了解,怎样禁止用户点击EDIT,又能正常显示文字吗?
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 313, 289, 226, 375)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 289, 265)
GUICtrlSetData(-1, "Edit1")
;~ GUICtrlSetState (-1, $GUI_DISABLE ) 
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

AdlibEnable("_Write", 300)
Global $i = 0

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd



Func _write()
        $i += 1
        GUICtrlSetData($Edit1,"这是行 " & $i & @crlf,"1")
EndFunc   ;==>_write

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2009-12-31 16:55:08 | 显示全部楼层
判断鼠标下的控件,是EDIT时将他移走,哈哈
发表于 2009-12-31 17:29:56 | 显示全部楼层
Func _write()
        $i += 1
                Send("^{end}")                             ;---------------------------- 加一句,哈哈
        GUICtrlSetData($Edit1,"这是行 " & $i & @crlf,"1")
EndFunc   ;==>_write
发表于 2009-12-31 17:37:15 | 显示全部楼层
本帖最后由 sanmoking 于 2009-12-31 17:45 编辑

上边有点开玩笑,下面给你一个我自己的方法。。。。。
如果有用,请哪位有钱人给加点花。。。


#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 313, 289, 226, 375)
$Edit1 = GUICtrlCreateEdit("", 1000000, 10000000, 289, 265)                  ;----------------有时候看不见的控件会起到很神奇的作用
$Edit2 = GUICtrlCreateEdit("", 8, 8, 289, 265)                  ;----------------窗体上显示出来的输入框
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###




For $i = 1 To 30
        _write()
Next


While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
WEnd

Func _write()
        GUICtrlSetData($Edit1, "这是行 " & $i & @CRLF, "1")                  ;----------------先把数据写到这个看不见的控件上
        GUICtrlSetData($Edit2,GUICtrlRead($Edit1),"")                  ;----------------在把它转到能看见的那个上面
        Sleep(500)
EndFunc   ;==>_write

评分

参与人数 1金钱 +10 收起 理由
顽固不化 + 10 想法很独特的哈

查看全部评分

发表于 2009-12-31 17:39:57 | 显示全部楼层
本帖最后由 sanmoking 于 2009-12-31 17:46 编辑

这是第二种方法,如下:
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 313, 289, 226, 375)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 289, 265)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$txt = ""                  ;----------------直接用个变量把你要显示的内容放在一块就好了嘛
For $i = 1 To 30
        $txt = $txt & "这是行 " & $i & @CRLF
        _write()
Next
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
WEnd
Func _write()
        GUICtrlSetData($Edit1,$txt)                  ;----------------每次更新全部内容就不怕用户干扰出错了
        Sleep(500)
EndFunc   ;==>_write
发表于 2009-12-31 17:41:20 | 显示全部楼层
本帖最后由 sanmoking 于 2009-12-31 17:47 编辑

这是最合理的方法:
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 313, 289, 226, 375)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 289, 265)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
For $i = 1 To 30
        _write()
Next
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
WEnd
Func _write()
        GUICtrlSetData($Edit1,GUICtrlRead($Edit1) & "这是行 " & $i & @CRLF)                  ;----------------这个方法很有用的,楼主应该能明白什么意思吧
        Sleep(500)
EndFunc   ;==>_write

评分

参与人数 1金钱 +10 收起 理由
itljl + 10

查看全部评分

发表于 2009-12-31 17:42:18 | 显示全部楼层
上面三个方法,各有各的用处,只是思路不同。。殊途同归。。。
发表于 2009-12-31 17:43:10 | 显示全部楼层
LS有创意。
 楼主| 发表于 2009-12-31 20:08:52 | 显示全部楼层
这是最合理的方法:
#include
#include
#include
#Region ### START Koda GUI section ### Form=
$ ...
sanmoking 发表于 2009-12-31 17:41


这种情况,滚动条不会自动往下的。。。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2009-12-31 20:09:56 | 显示全部楼层
回复 5# sanmoking


    这个方法不行的,因为更新数据是在有数据的情况下,不能用一个循环将数据加起来。
 楼主| 发表于 2009-12-31 20:10:58 | 显示全部楼层
上边有点开玩笑,下面给你一个我自己的方法。。。。。
如果有用,请哪位有钱人给加点花。。。


#inclu ...
sanmoking 发表于 2009-12-31 17:37


这个亦是滚动条不会自动往下。
发表于 2009-12-31 20:25:21 | 显示全部楼层
_GUICtrlEdit_SetReadOnly($Edit1, True)
发表于 2009-12-31 20:54:54 | 显示全部楼层
_GUICtrlEdit_SetReadOnly($Edit1, True)
pcbar 发表于 2009-12-31 20:25


老大这个跟设置属性为readonly是一样的,字是清楚了,但还没达到lz的要求:不能乱
发表于 2009-12-31 21:32:17 | 显示全部楼层
回复 11# itljl


    试试这个,不过这个也是会有用户干扰的现象,,,用户单纯的鼠标点击不会影响,用户拖选一部分文字就会有影响啦,另外这个不支持汉字,汗,没仔细看是怎么回事.下一楼会有另一个例子,等下我哦,不要插队...


#Include <GuiEdit.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 313, 289, 226, 375)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 289, 265)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
For $i = 1 To 50
        _write()
Next
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
WEnd
Func _write()
;~         GUICtrlSetData($Edit1,GUICtrlRead($Edit1) & "这是行 " & $i & @CRLF)                  ;----------------这个方法很有用的,楼主应该能明白什么意思吧
        _GUICtrlEdit_InsertText($Edit1,$i &" "& Chr(10), _GUICtrlEdit_GetTextLen($Edit1) )               
                Sleep(10)
EndFunc   ;==>_write
发表于 2009-12-31 21:36:49 | 显示全部楼层
这个应该会完美解决楼主的问题了,,,给我打打的加花,....鼓掌...口哨....哈哈哈啊啊啊啊啊啊

#Include <GuiEdit.au3>
#Include <ScrollBarConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 313, 150, 226, 375)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 289, 130)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
For $i = 1 To 30
        _write()
Next
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
WEnd
Func _write()
        GUICtrlSetData($Edit1,GUICtrlRead($Edit1) & "这是行 " & $i & @CRLF)                  ;----------------这个方法很有用的,楼主应该能明白什么意思吧
                _GUICtrlEdit_Scroll($Edit1, $SB_SCROLLCARET)
                Sleep(500)
EndFunc   ;==>_write

评分

参与人数 1金钱 +10 收起 理由
itljl + 10

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-28 02:14 , Processed in 0.103799 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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