找回密码
 加入
搜索
查看: 3559|回复: 9

[AU3基础] 【已解决】关于Lab控件中的文字滚动问题,请求帮助

  [复制链接]
发表于 2010-7-16 02:19:58 | 显示全部楼层 |阅读模式
本帖最后由 styledream 于 2010-7-16 17:26 编辑

请问如何在文字宽度大于Lab控件宽度时,使其有自动滚动的效果
就像歌词的滚动一样,从右向左滚动

解决方法见 5#
#include <Misc.au3>
#include <File.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


If _Singleton(@ScriptName, 1) = 0 Then Exit (1) ;互斥运行

Dim $rnd[3],$ver, $aRecords, $LabSentence

$hGUI = GUICreate("关于文字滚动的问题", 400, 60, -1, -1)
$LabSentence = GUICtrlCreateLabel("", 5, 10, 380, 20, $SS_CENTER, $GUI_WS_EX_PARENTDRAG)
$BtnOpenFile = GUICtrlCreateButton("打开文件", 5, 35, 60, 25)

OriFile()  ;初始化程序
AdlibRegister("ChangeSentence", 10000)  ;10秒后自动切换句子
GUISetState()

Do
        $msg = GUIGetMsg()
        Switch ($msg)
                Case $BtnOpenFile
                        OpenFile()                
        EndSwitch
Until $msg = $GUI_EVENT_CLOSE

Func OriFile()  ;程序运行后的初始化函数
        Dim $szDrive, $szDir, $szFName, $szExt
        $txtFile = IniRead(".\Setting.ini", "Setting", "File", "NotFound")
        
        If _FileReadToArray($txtFile, $aRecords) Then  ;把文件读入数组
                If $txtFile <> "" Then
                        For $x = 1 To $aRecords[0]
                                $ver = $ver & $aRecords[$x] & @CRLF
                        Next
                        ChangeSentence()
                Else
                        MsgBox(0, "Error", "读取文件失败!")
                EndIf
        Else
                _PathSplit($txtFile, $szDrive, $szDir, $szFName, $szExt)  ;拆分文件路径
                MsgBox(0, "Error", "文件 “" & $szFName & $szExt & "” 不存在,请重新选取文件!")
        EndIf
EndFunc   ;==>OriFile

Func OpenFile()   ;打开文件函数
        $txtFile = FileOpenDialog("打开文件", @WorkingDir, "文本文件 (*.txt)", 1 + 2 + 8)
        
        If $txtFile <> "" Then
                If _FileReadToArray($txtFile, $aRecords) Then  ;把文件读入数组
                        For $x = 1 To $aRecords[0]  ;用换行符格式化数组
                                $ver = $ver & $aRecords[$x] & @CRLF
                        Next
                        ChangeSentence()  ;变换句子
                        IniWrite(".\Setting.ini", "Setting", "File", $txtFile)  ;将文件路径写入配置文件
                Else
                        MsgBox(0, "Error", "读取文件失败!")
                EndIf
        EndIf
EndFunc   ;==>OpenFile

Func ChangeSentence()  ;变换句子函数
        $rnd[0] = $rnd[2]  ;读取正确的非空语句
        $rnd[1] = Random(1, $aRecords[0], 1)  ;随机生成一个新的下一句
        If $aRecords[$rnd[1]]=="" Or $rnd[1]=$rnd[2] Then  ;空行则或随机重复则重新生成
                ChangeSentence()
        Else
                $rnd[2] = $rnd[1]  ;存储非空的上一句下标
                GUICtrlSetData($LabSentence, $aRecords[$rnd[1]])
        EndIf
EndFunc   ;==>ChangeSentence
测试用例(复制以下两行并保存为“测试.txt"):
0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
零一二三四五六七八九哟零一二三四五六七八九吮零一二三四五六七八九嘿零一二三四五六七八九懊

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-7-16 07:03:44 | 显示全部楼层
学习了......
 楼主| 发表于 2010-7-16 10:39:35 | 显示全部楼层
没有人知道怎么解决吗
发表于 2010-7-16 10:48:48 | 显示全部楼层
发表于 2010-7-16 10:51:54 | 显示全部楼层
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=

Global $Y=120
$Form1 = GUICreate("字移动", 322, 205, -1, -1)
GUICtrlSetFont(-1, 24, 800, 0, "黑体")
$Label1 = GUICtrlCreateLabel("字移动的例子", 64, 24, 202, 37)
GUICtrlSetFont(-1, 24, 800, 0, "黑体")
GUISetState(@SW_SHOW,$Form1)

$Form2=GUICreate("", 322, 120, 0, 100, $WS_POPUP,  $WS_EX_MDICHILD, $Form1)
$Label2 = GUICtrlCreateLabel("     字移动的例子"&@CRLF&"  欢迎访问初级视编室"&@CRLF&"http://dvedit.5d6d.com", 0, 120, 202, 50)
GUICtrlSetFont(-1, 12, 800, 0, "黑体")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetCursor (-1, 0)
GUISetState(@SW_SHOW,$Form2)

#EndRegion ### END Koda GUI section ###
AdlibRegister ( "_IDmov",100 )

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Label2
                        ShellExecute("http://dvedit.5d6d.com")
        EndSwitch
WEnd

Func _IDmov()
        $Y=$Y-3
        If $Y<-50 then $Y=120
        GUICtrlSetPos($Label2,70,$Y)
EndFunc
 楼主| 发表于 2010-7-16 12:10:41 | 显示全部楼层
回复 5# rikthhpgf2005

原来是我的搜索关键字没写准,难怪搜不出相关的帖子
感谢“rikthhpgf2005 兄弟”的帮助,先来去研究一下
 楼主| 发表于 2010-7-16 12:57:38 | 显示全部楼层
回复 5# rikthhpgf2005

每次读取的字符长度都不同,如何根据字符的长度创建Lab控件
发表于 2010-7-16 15:56:19 | 显示全部楼层
回复 6# styledream


    不用谢谢,互相学习
发表于 2010-7-17 09:49:04 | 显示全部楼层
来学习下。。
发表于 2010-9-14 16:23:14 | 显示全部楼层
这个是向上移动的,向左移动的呢?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-10-3 08:24 , Processed in 0.083377 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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