找回密码
 加入
搜索
查看: 544|回复: 19

[AU3基础] 【已解决】GUICtrlCreateListView 标签对齐问题

[复制链接]
发表于 2023-8-13 20:10:33 | 显示全部楼层 |阅读模式
本帖最后由 h111666b 于 2023-8-13 22:54 编辑


代码如下,


#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

;行间隔不能更改
$aLines = "1:1  F1     503T      798  重量   5000      公斤"

Local $aInfo = StringSplit($aLines, " ")

; 创建GUI窗口
Local $hGUI = GUICreate("ListView Example", 400, 300)

; 创建ListView控件
Local $hListView = GUICtrlCreateListView("比例|出错|TT|数据|载重|数据|重量", 10, 10, 380, 280)
; 将分割的项目写入到ListView控件的标签中
GUICtrlCreateListViewItem($aInfo[1] & "|" & $aInfo[2] & "|" & $aInfo[3] & "|" & $aInfo[4] & "|" & $aInfo[5] & "|" & $aInfo[6] & "|" & $aInfo[7], $hListView)

GUISetState(@SW_SHOW)

While 1
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                        ExitLoop
        EndSwitch
WEnd

GUIDelete()


$aLines 里面字符怎么对齐对到GUICtrlCreateListView 标签,分别是7个标签对应7个数据,在线求助!


发表于 2023-8-13 21:07:53 | 显示全部楼层
本帖最后由 qq413774005 于 2023-8-13 21:26 编辑

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
;#include <GuiListView.au3>;列表窗口
;行间隔不能更改
$aLines = "1:1  F1     503T      798  重量   5000      公斤"
$aLines = StringReplace($aLines, "  ", ",");两个空格替换
$aLines = StringStripWS($aLines, 8);清除多的空格;得到的数据为 1:1,F1,,503T,,,798,重量,5000,,,公斤
$a = StringSplit($aLines, ",");做为数组分隔
; 创建GUI窗口
Local $hGUI = GUICreate("ListView Example", 400, 300)
; 创建ListView控件
Local $hListView = GUICtrlCreateListView("比例|出错|TT|数据|载重|数据|重量", 10, 10, 380, 280)
; 将分割的项目写入到ListView控件的标签中
GUICtrlCreateListViewItem($a[1] & "|" & $a[2] & "|" & $a[4] & "|" & $a[7] & "|" & $a[8] & "|" & $a[9] & "|" & $a[12], $hListView)
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
   ExitLoop
EndSwitch
WEnd
GUIDelete()

发表于 2023-8-13 21:08:19 | 显示全部楼层
本帖最后由 qq413774005 于 2023-8-13 21:28 编辑
qq413774005 发表于 2023-8-13 21:07
#include
#include
#include

这个是你想要的,但有一个问题就是两个数据间一定要有两个空格。
 楼主| 发表于 2023-8-13 21:44:28 | 显示全部楼层
我先试下,感谢
发表于 2023-8-13 22:32:44 | 显示全部楼层
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
;行间隔不能更改
$aLines = "1:1 | F1  |   503T   |   798 | 重量  | 5000   |   公斤"
Local $aInfo = StringSplit($aLines, "|")
; 创建GUI窗口
Local $hGUI = GUICreate("ListView Example", 400, 300)
; 创建ListView控件
Local $hListView = GUICtrlCreateListView("比例|出错|TT|数据|载重|数据|重量", 10, 10, 380, 280)
; 将分割的项目写入到ListView控件的标签中
GUICtrlCreateListViewItem($aInfo[1] & "|" & $aInfo[2] & "|" & $aInfo[3] & "|" & $aInfo[4] & "|" & $aInfo[5] & "|" & $aInfo[6] & "|" & $aInfo[7], $hListView)
GUISetState(@SW_SHOW)
While 1
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                        ExitLoop
        EndSwitch
WEnd
GUIDelete()


 楼主| 发表于 2023-8-13 22:53:53 | 显示全部楼层
谢谢楼上,2个回复都很实用,感谢
发表于 2023-8-14 08:30:32 | 显示全部楼层
h111666b 发表于 2023-8-13 22:53
谢谢楼上,2个回复都很实用,感谢

昨晚没详细看你的要求:

;行间隔不能更改
$aLines = "1:1  F1     503T      798  重量   5000      公斤"


#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
;行间隔不能更改
;$aLines = "1:1 | F1  |   503T   |   798 | 重量  | 5000   |   公斤"
$aLines = "1:1  F1     503T      798  重量   5000      公斤"
$aLines = StringReplace($aLines, "      ", "  ");两个空格替换
$aLines = StringReplace($aLines, "     ", "  ");两个空格替换
$aLines = StringReplace($aLines, "   ", "  ");两个空格替换
$aLines = StringRegExpReplace($aLines, "  ", "|");两个空格替换
$aLines = StringStripWS($aLines, 8);清除多的空格
Local $aInfo = StringSplit($aLines, "|")
; 创建GUI窗口
Local $hGUI = GUICreate("ListView Example", 400, 300)
; 创建ListView控件
Local $hListView = GUICtrlCreateListView("比例|出错|TT|数据|载重|数据|重量", 10, 10, 380, 280)
; 将分割的项目写入到ListView控件的标签中
GUICtrlCreateListViewItem($aInfo[1] & "|" & $aInfo[2] & "|" & $aInfo[3] & "|" & $aInfo[4] & "|" & $aInfo[5] & "|" & $aInfo[6] & "|" & $aInfo[7], $hListView)
GUISetState(@SW_SHOW,$hGUI)
MsgBox($MB_SYSTEMMODAL, "结果", $aLines)
While 1
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                        ExitLoop
        EndSwitch
WEnd
GUIDelete()


 楼主| 发表于 2023-8-14 10:00:11 | 显示全部楼层
$aLines 变量写入文本后是以下内容:

1:1  F1     503T      798  重量   5000      公斤
1:1  F1     470T      798  重量   4730      公斤
1:1  F1     200T      798  重量   2555      公斤
1:1  F1     13T       798  重量   1458      公斤
1:1  F1     805T      798  重量   9210      公斤

现在只能写入第一行,其它行就看不到了
发表于 2023-8-14 14:41:40 | 显示全部楼层
本帖最后由 chzj589 于 2023-8-14 16:30 编辑
h111666b 发表于 2023-8-14 10:00
$aLines 变量写入文本后是以下内容:

1:1  F1     503T      798  重量   5000      公斤

只读取一行,就显示一行。
要全部读取,才能全部显示
应该用读取文本后显示列表
变量写入文本时要考虑格式,方便读取显示在列表



本帖子中包含更多资源

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

×
 楼主| 发表于 2023-8-14 17:18:12 | 显示全部楼层
本帖最后由 h111666b 于 2023-8-14 17:19 编辑
chzj589 发表于 2023-8-14 14:41
只读取一行,就显示一行。
要全部读取,才能全部显示
应该用读取文本后显示列表

帮忙给个示例,现在就是使用StdoutRead读取后 写入文本显示以上内容,就是需要你现在这第一个示例,带表格模式
发表于 2023-8-14 17:30:38 | 显示全部楼层
h111666b 发表于 2023-8-14 17:18
帮忙给个示例,现在就是使用StdoutRead读取后 写入文本显示以上内容,就是需要你现在这第一个示例,带表 ...

_FileReadToArray
读取文件内容到 1D 或 2D 数组.


发表于 2023-8-14 18:15:04 | 显示全部楼层
h111666b 发表于 2023-8-14 17:18
帮忙给个示例,现在就是使用StdoutRead读取后 写入文本显示以上内容,就是需要你现在这第一个示例,带表 ...

把你要读取的文本文件发上来看看 
 楼主| 发表于 2023-8-14 18:36:36 | 显示全部楼层
chzj589 发表于 2023-8-14 17:30
_FileReadToArray
读取文件内容到 1D 或 2D 数组.


1:1  F1     503T      798  重量   5000      公斤
1:1  F1     470T      798  重量   4730      公斤
1:1  F1     200T      798  重量   2555      公斤

_FileReadToArray 读取后分行了,以上3行分别单行显示了, 单独一行按照楼上示例可以添加,读取几行后同时添加就不会了,就跟你示例的第一个视图一样?
 楼主| 发表于 2023-8-14 18:43:54 | 显示全部楼层
本帖最后由 h111666b 于 2023-8-14 18:45 编辑
chzj589 发表于 2023-8-14 18:15
把你要读取的文本文件发上来看看 

文本.txt打开后的视图如下,

1:1  F1     503T      798  重量   5000       公斤
1:1  F1     470T    798  重量   4730       公斤
1:1  F1     200T   798  重量   2555       公斤
1:1  F1     13T       798  重量   1458       公斤
1:1  F1     805T    798  重量   9210       公斤


其中都有空格,但是空格最小的有2个,大的有4个
发表于 2023-8-14 18:46:52 | 显示全部楼层
本帖最后由 chzj589 于 2023-8-14 18:55 编辑
h111666b 发表于 2023-8-14 18:36
1:1  F1     503T      798  重量   5000      公斤
1:1  F1     470T      798  重量   4730      公 ...

cc.ini文件
1:1 | F1|503T|798 | 重量|5000|公斤
1:1 | F1|470T|798 | 重量|4730|公斤
1:1 | F1|200T|798 | 重量|2555|公斤
1:1 | F1|13T |798 | 重量|1458|公斤
1:1 | F1|805T|798 | 重量|9210|公斤
1:1 | F1|503T|798 | 重量|5000|公斤
1:1 | F1|470T|798 | 重量|4730|公斤
1:1 | F1|200T|798 | 重量|2555|公斤
1:1 | F1|13T |798 | 重量|1458|公斤
1:1 | F1|805T|798 | 重量|9210|公斤
1:1 | F1|503T|798 | 重量|5000|公斤
1:1 | F1|470T|798 | 重量|4730|公斤
1:1 | F1|200T|798 | 重量|2555|公斤
1:1 | F1|13T |798 | 重量|1458|公斤
1:1 | F1|805T|798 | 重量|9210|公斤

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <file.au3>
Local $txt_array1, $y = 0, $z = 0
; 创建GUI窗口
Local $hGUI = GUICreate("ListView Example", 440, 500)
; 创建ListView控件
Local $hListView = GUICtrlCreateListView("id|比例|出错|TT |数据 |载重|数据 |重量", 10, 10, 420, 480, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS))
$hListView1 = GUICtrlGetHandle($hListView)
;GUICtrlSetBkColor(-1, $CLR_MONEYGREEN);0xC0C0C0); 背景色
GUICtrlSetBkColor(-1, 0xC0E0FF)
;GUICtrlSetColor(-1, 0x990000)
GUICtrlSetFont(-1, 9, 400, 0, 'Arial');"微软雅黑")
; 设置颜色
_GUICtrlListView_SetBkColor($hListView, 14675183);$CLR_MONEYGREEN)
_GUICtrlListView_RegisterSortCallBack($hListView)
$hImage = _GUIImageList_Create(1, 20)
_GUICtrlListView_SetImageList($hListView1, $hImage, 1)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_INFOTIP))
GUISetState(@SW_SHOW, $hGUI)
_du()
While 1
 Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
   ExitLoop
 EndSwitch
WEnd
GUIDelete()
Func _du()
 _FileReadToArray('cc.ini', $txt_array1)
 Local $txt_array[UBound($txt_array1)][8]
 For $i = 0 To UBound($txt_array) - 1
  Local $aInfo = StringSplit($txt_array1[$y], "|")
  For $ii = 1 To $aInfo[0]
   $txt_array[$i][0] = $y
   $txt_array[$i][$ii] = $aInfo[$ii];& "|"
   $z = $i
  Next
  $y += 1
 Next
 _ArrayDelete($txt_array, 0)
 ;_ArrayDisplay($txt_array, "2D 数组") ; 显示当前数组.
 Global $eExcelArray3[$z][8]
 $eExcelArraya = _ArrayTo2D($txt_array, 1)
 For $n = 0 To UBound($eExcelArraya) - 1
  For $i = 0 To UBound($eExcelArraya, 2) - 1
   $eExcelArray3[$n][$i] = $eExcelArraya[$n][$i]
  Next
 Next
 ;_ArrayDisplay($eExcelArray3, "2D 数组");"整行查询   ", "", "64")
 GUICtrlSendMsg($hListView, $LVM_DELETEALLITEMS, 0, 0)
 ; 将分割的项目写入到ListView控件的标签中
 _GUICtrlListView_AddArray($hListView, $eExcelArray3)
 ;_ArrayDisplay($eExcelArray3, "2D 数组", "", "64")
EndFunc   ;==>_du
Func _ArrayTo2D($array, $iNum = 2)
 If Mod(UBound($array), $iNum) Or (Not IsArray($array)) Or UBound($array, 2) Then Return SetError(1, 0, $array)
 Local $aRet[UBound($array) / $iNum][$iNum]
 For $i = 0 To UBound($array) - 1
  $aRet[Int($i / $iNum)][Mod($i, $iNum)] = $array[$i]
 Next
 Return $aRet
EndFunc   ;==>_ArrayTo2D





本帖子中包含更多资源

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

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

本版积分规则

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

GMT+8, 2024-5-2 16:48 , Processed in 0.081736 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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