【发布时间】:2014-10-30 02:53:16
【问题描述】:
我在我的 vb.net 代码中执行了以下步骤:
从文本文件中获取包含我想要的值的行,在我的情况下,我需要最后一个值作为“组”
创建一个picturebox数组,picturebox的个数就是步骤1的个数。1行有2个picturebox。
之后,我想将从文本文件中读取的图像设置为 1 到 1 的图片框(图片名称是第二个 value.jpg),但我还没有找到合适的方法。
有什么建议吗?
我的文本文件如下:
到目前为止我的代码是:
Private PicBoxArray(9) As PictureBox
Dim value0 As String
Dim value1 As String
Dim value2 As String
Dim value3 As String
Dim fileName As String = "D:\local\MyTest1.txt"
Dim subString1 As String = "Group"
Dim lines As String() = File.ReadAllLines(fileName)
For i As Integer = 0 To lines.Length - 1
If lines(i).Contains(subString1) Then
count1 += 1
end if
Next
For i = 1 To count1
PicBoxArray(i) = New PictureBox
With PicBoxArray(i)
.Tag = i
.Size = New Size(330, 280)
If i Mod 2 = 0 Then
.Location = New Point(430, 80 + 300 * ((i - 2) / 2))
Else
.Location = New Point(80, 80 + 300 * ((i - 1) / 2))
End If
.Parent = Me
.Visible = True
End With
Next
Using MyReader As New Microsoft.VisualBasic.
FileIO.TextFieldParser("D:\PUB_GIS_Tagging\local\MyTest.txt")
Dim lineCount = File.ReadAllLines("D:\PUB_GIS_Tagging\local\MyTest.txt").Length
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
Dim currentRow As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
value0 = currentRow(0)
value1 = currentRow(1)
value2 = currentRow(2)
value3 = currentRow(3)
If value3 = "Group"
'======= put the picture from PicBoxArray(1) to PicBoxArray(count1) i by 1========
'====================== I am stuck here=============
End if
Catch ex As Microsoft.VisualBasic.
FileIO.MalformedLineException
MsgBox("Line " & ex.Message &
"is not valid and will be skipped.")
End Try
End While
End Using
【问题讨论】:
标签: vb.net picturebox