找回密码
 加入
搜索
查看: 1912|回复: 8

[网络通信] 【已解决】如何删除Label控件所创分页多余信息

[复制链接]
发表于 2019-7-22 14:52:23 | 显示全部楼层 |阅读模式
本帖最后由 dnvplj 于 2019-7-22 18:42 编辑

请问各位朋友, 到最后一页,还是显示第上页的部分信息,如何将其删除,只显示最后一页的信息,见下图。

说明:代码是本论坛 afan 大的,原代码是用“listview”创建的分页,我改为“Label”创建的分页
源码地址:http://autoitx.com/forum.php?mod ... =1&authorid=7644923
#include <GuiListView.au3>
#include <WindowsConstants.au3>


$IniFile = @ScriptDir & "\Config.ini"
$var = _IniReaNames($IniFile)
If @error Then Exit MsgBox(48, "出错!", "发生错误,INI文件读取失败!") ;INI文件读取错误将退出
Dim $iChange = 11, $dqyc = 1 ;$iChange 每页显示多少个项目;$dqyc 为当前页次
Dim $zys = Ceiling($var[0][0] / $iChange)

GUICreate("Listview分页显示", 400, 450)

$Button1 = GUICtrlCreateButton("<", 110, 400, 30, 22)
$Button2 = GUICtrlCreateButton(">", 190, 400, 30, 22)
$Label = GUICtrlCreateLabel('1', 143, 405, 18, 17, 0x0002)
GUICtrlCreateLabel('/' & $zys, 162, 405, 23, 17)
$Button3 = GUICtrlCreateButton("返回首页", 30, 400, 80, 22)
$Button4 = GUICtrlCreateButton("跳至尾页", 220, 400, 80, 22)
$Combo = GUICtrlCreateCombo('', 305, 402, 60, 22)
$Combodata = ''
For $i = 1 To $zys
        $Combodata &= '第' & $i & '页|'
Next
GUICtrlSetData(-1, $Combodata, '第1页')
GUISetState()

Go(1) ;首次读取

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $Button1 ;上一页
                        Go($dqyc - 1)
                Case $Button2 ;下一页
                        Go($dqyc + 1)
                Case $Button3 ;首页
                        Go(1)
                Case $Button4 ;尾页
                        Go($zys)
                Case $Combo ;下拉选择页次
                        Go(StringRegExpReplace(GUICtrlRead($Combo), '[^\d]', ''))
        EndSwitch
WEnd

Func Go($yc)
        Local $iNo1 = ($yc - 1) * $iChange + 1
        Local $iNo2
        If $yc = $zys Then
                $iNo2 = $var[0][0]
                SetState(64, 128, 64, 128)
        ElseIf $yc = 1 Then
                $iNo2 = $iNo1 + $iChange - 1
                SetState(128, 64, 128, 64)
        Else
                $iNo2 = $iNo1 + $iChange - 1
                SetState(64, 64, 64, 64)
        EndIf
        Read($iNo1, $iNo2)
        GUICtrlSetData($Label, $yc)
        GUICtrlSetData($Combo, '第' & $yc & '页')
        $dqyc = $yc
EndFunc   ;==>Go

Func SetState($1, $2, $3, $4)
        GUICtrlSetState($Button1, $1)
        GUICtrlSetState($Button2, $2)
        GUICtrlSetState($Button3, $3)
        GUICtrlSetState($Button4, $4)
EndFunc   ;==>SetState

Func Read($iNo1, $iNo2)
        Local $s = 1
        For $i = $iNo1 To $iNo2
                GUICtrlCreateLabel($i & '、 ' & $var[$i][1], 45, 10 + $s * 30, 130, 28)
                $s += 1
        Next
EndFunc   ;==>Read

Func _IniReaNames($IniFile)
        Local Const $N = 2
        Local $var[1][$N], $p = 1
        Local $i = 1
        While 1
                Local $ClsName = IniRead($IniFile, $i, "test", "")
                If $ClsName = "" Then ExitLoop
                ReDim $var[$p + 1][$N]
                $var[$p][1] = IniRead($IniFile, $i, "test", "")
                $p += 1
                $i += 1
        WEnd
        $var[0][0] = UBound($var, 1) - 1
        Return $var
EndFunc   ;==>_IniReaNames

本帖子中包含更多资源

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

×
发表于 2019-7-22 15:15:31 | 显示全部楼层
你这每点击一次翻页就创建了一列控件  生命不息 创建不止…
应该先创建所有并隐藏,需要时显示对应的。

BTW, 测试至少得要提供可测试的基本条件,ini文件呢? 没有就创建…
$IniFile = @ScriptDir & "\Config.ini"
If Not FileExists($IniFile) Then
        Local $sini = ''
        For $ii = 1 To 30
                $sini &= '[' & $ii & ']' & @CRLF & 'test = 第' & $ii & '测试项目' & @CRLF
        Next
        Local $hFO = FileOpen($IniFile, 2 + 8 + 512)
        FileWrite($hFO, $sini)
        FileClose($hFO)
EndIf
 楼主| 发表于 2019-7-22 17:34:49 | 显示全部楼层
本帖最后由 dnvplj 于 2019-7-22 17:41 编辑
afan 发表于 2019-7-22 15:15
你这每点击一次翻页就创建了一列控件  生命不息 创建不止…
应该先创建所有并隐藏,需要时显示对应的。

...

afan大,真是对不起,配置文件已上传,但配置文件不是固定的,也可能在加“关键字和值”。
发表于 2019-7-22 18:20:29 | 显示全部楼层
Global $aIniData = _IniReaNames(@ScriptDir & '\Config.ini')
Global $iChange = 11, $nPageNow = 1 ;$iChange 每页显示多少个项目;$nPageNow 为当前页次
Global $nCount = Ceiling($aIniData[0][0] / $iChange)
Global $Button1, $Button2, $Button3, $Button4, $Label, $Combo, $aILabel, $aLast[2]
_GUICreate()
_PageChange(1) ;首次读取

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $Button1 ;上一页
                        _PageChange($nPageNow - 1)
                Case $Button2 ;下一页
                        _PageChange($nPageNow + 1)
                Case $Button3 ;首页
                        _PageChange(1)
                Case $Button4 ;尾页
                        _PageChange($nCount)
                Case $Combo ;下拉选择页次
                        _PageChange(StringRegExpReplace(GUICtrlRead($Combo), '[^\d]', ''))
        EndSwitch
WEnd

Func _GUICreate()
        GUICreate('Label 控件列 分页显示', 400, 450)
        Dim $Button1 = GUICtrlCreateButton('<', 110, 400, 30, 22)
        Dim $Button2 = GUICtrlCreateButton('>', 190, 400, 30, 22)
        Dim $Label = GUICtrlCreateLabel('1', 143, 405, 18, 17, 0x0002)
        GUICtrlCreateLabel('/' & $nCount, 162, 405, 23, 17)
        Dim $Button3 = GUICtrlCreateButton('返回首页', 30, 400, 80, 22)
        Dim $Button4 = GUICtrlCreateButton('跳至尾页', 220, 400, 80, 22)
        Dim $Combo = GUICtrlCreateCombo('', 305, 402, 60, 22, 0x3)
        Local $Combodata = ''
        For $i = 1 To $nCount
                        $Combodata &= '第' & $i & '页|'
        Next
        GUICtrlSetData(-1, $Combodata, '第1页')
        Dim $aILabel = _CreateAll()
        GUISetState()
EndFunc   ;==>_GUICreate()

Func _PageChange($yc)
        Local $iNo1 = ($yc - 1) * $iChange + 1
        Local $iNo2
        If $yc = $nCount Then
                $iNo2 = $aIniData[0][0]
                _SetState(64, 128, 64, 128)
        ElseIf $yc = 1 Then
                $iNo2 = $iNo1 + $iChange - 1
                _SetState(128, 64, 128, 64)
        Else
                $iNo2 = $iNo1 + $iChange - 1
                _SetState(64, 64, 64, 64)
        EndIf
        _Show($iNo1, $iNo2)
        GUICtrlSetData($Label, $yc)
        GUICtrlSetData($Combo, '第' & $yc & '页')
        $nPageNow = $yc
EndFunc   ;==>_PageChange

Func _SetState($1, $2, $3, $4)
        GUICtrlSetState($Button1, $1)
        GUICtrlSetState($Button2, $2)
        GUICtrlSetState($Button3, $3)
        GUICtrlSetState($Button4, $4)
EndFunc   ;==>_SetState

Func _Show($iNo1, $iNo2)
        If $aLast[0] Then
                For $ii = $aLast[0] To $aLast[1]
                        GUICtrlSetState($aILabel[$ii], 32)
                Next
        EndIf
        For $ii = $iNo1 To $iNo2
                GUICtrlSetState($aILabel[$ii], 16)
        Next
        Dim $aLast[2] = [$iNo1, $iNo2]
EndFunc   ;==>_Show

Func _CreateAll()
        Local $aC[$aIniData[0][0] + 1]
        For $ii = 1 To $aIniData[0][0]
                $aC[$ii] = GUICtrlCreateLabel($ii & '、 ' & $aIniData[$ii][1], 45, 30 * Mod($ii - 1, $iChange) + 40, 130, 28)
                GUICtrlSetState(-1, 32)
        Next
        Return $aC
EndFunc   ;==>_CreateAll

Func _IniReaNames($IniFile)
        If Not FileExists($IniFile) Then
                Local $sini = ''
                For $ii = 1 To 30
                        $sini &= '[' & $ii & ']' & @CRLF & 'test = 第' & $ii & '测试项目' & @CRLF
                Next
                Local $hFO = FileOpen($IniFile, 2 + 8 + 512)
                FileWrite($hFO, $sini)
                FileClose($hFO)
        EndIf
        Local Const $N = 2
        Local $aIniData[1][$N], $p = 1
        Local $i = 1
        While 1
                Local $ClsName = IniRead($IniFile, $i, 'test', '')
                If $ClsName = '' Then ExitLoop
                ReDim $aIniData[$p + 1][$N]
                $aIniData[$p][1] = IniRead($IniFile, $i, 'test', '')
                $p += 1
                $i += 1
        WEnd
        $aIniData[0][0] = UBound($aIniData, 1) - 1
        Return $aIniData
EndFunc   ;==>_IniReaNames
 楼主| 发表于 2019-7-22 18:36:34 | 显示全部楼层

请问 afan 大,第93至101行起什么作用?
发表于 2019-7-22 18:38:52 | 显示全部楼层
dnvplj 发表于 2019-7-22 18:36
请问 afan 大,第93至101行起什么作用?

方便任何人测试脚本,无需另外下载 ini 文件(如无会自动生成)

评分

参与人数 1金钱 +40 收起 理由
dnvplj + 40 很给力!

查看全部评分

发表于 2019-7-22 19:24:21 | 显示全部楼层
dnvplj 发表于 2019-7-22 17:34
afan大,真是对不起,配置文件已上传,但配置文件不是固定的,也可能在加“关键字和值”。


#include <WindowsConstants.au3>

Global $IniFile = @ScriptDir & "\Config.ini"
$var = _IniReaNames($IniFile)
If @error Then Exit MsgBox(48, "出错!", "发生错误,INI文件读取失败!") ;INI文件读取错误将退出
Dim $iChange = 10, $dqyc = 1 ;$iChange 每页显示多少个项目;$dqyc 为当前页次
Dim $zys = Ceiling($var[0][0] / $iChange)
Global $var[20][3]
GUICreate("Label分页显示", 400, 450)
$Button1 = GUICtrlCreateButton("<", 110, 400, 30, 22)
$Button2 = GUICtrlCreateButton(">", 190, 400, 30, 22)
$Label = GUICtrlCreateLabel('1', 143, 405, 18, 17, 0x0002)
GUICtrlCreateLabel('/' & $zys, 162, 405, 23, 17)
$Button3 = GUICtrlCreateButton("返回首页", 30, 400, 80, 22)
$Button4 = GUICtrlCreateButton("跳至尾页", 220, 400, 80, 22)
$Combo = GUICtrlCreateCombo('', 305, 402, 60, 22)
$Combodata = ''
For $i = 1 To $zys
        $Combodata &= '第' & $i & '页|'
Next
GUICtrlSetData(-1, $Combodata, '第1页')
GUISetState()
Go(1) ;首次读取
Go($dqyc + 2)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $Button1 ;上一页
                        Go($dqyc - 1)
                Case $Button2 ;下一页
                        Go($dqyc + 1)
                Case $Button3 ;首页
                        Go(1)
                Case $Button4 ;尾页
                        Go($zys)
                Case $Combo ;下拉选择页次
                        Go(StringRegExpReplace(GUICtrlRead($Combo), '[^\d]', ''))
        EndSwitch
WEnd
Func Go($yc)
        Local $iNo1 = ($yc - 1) * $iChange + 1
        Local $iNo2
        If $yc = $zys Then
                $iNo2 = $var[0][0]
                SetState(64, 128, 64, 128)
        ElseIf $yc = 1 Then
                $iNo2 = $iNo1 + $iChange - 1
                SetState(128, 64, 128, 64)
        Else
                $iNo2 = $iNo1 + $iChange - 1
                SetState(64, 64, 64, 64)
        EndIf
        Read($iNo1, $iNo2)
        GUICtrlSetData($Label, $yc)
        GUICtrlSetData($Combo, '第' & $yc & '页')
        $dqyc = $yc
EndFunc   ;==>Go

Func SetState($1, $2, $3, $4)
        GUICtrlSetState($Button1, $1)
        GUICtrlSetState($Button2, $2)
        GUICtrlSetState($Button3, $3)
        GUICtrlSetState($Button4, $4)
EndFunc   ;==>SetState

Func Read($iNo1, $iNo2)
        $var = _IniReaNames($IniFile)
        Local $s = 1
        For $i = $iNo1 To $iNo2
                GUICtrlCreateLabel($i & '、 ' & $var[$i][1], 45, 10 + $s * 30, 130, 28)
                $s += 1
        Next
EndFunc   ;==>Read

Func _IniReaNames($IniFile)
        Local Const $N = 2
        Local $var[1][$N], $p = 1
        Local $i = 1
        While 1
                Local $ClsName = IniRead($IniFile, $i, "test", "")
                If $ClsName = "" Then ExitLoop
                ReDim $var[$p + 1][$N]
                $var[$p][1] = IniRead($IniFile, $i, "test", "")
                $p += 1
                $i += 1
        WEnd
        $var[0][0] = UBound($var, 1) - 1
        Return $var
EndFunc   ;==>_IniReaNames
 楼主| 发表于 2019-7-22 19:38:57 | 显示全部楼层

感谢回复,运行该代码就直接显示第3页。
发表于 2019-7-23 00:07:34 | 显示全部楼层
不错支持一下
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-2 19:36 , Processed in 0.077963 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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