0

这是我的代码:

Public Class Form1

Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim FindFolder As New FolderBrowserDialog
    FindFolder.ShowDialog()
    TextBox1.Text = FindFolder.SelectedPath
End Sub

Public Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
    Try
        My.Settings.theSetPath = TextBox1.Text
        My.Settings.isValidPath = True
        My.Settings.Save()
        TextBox1.Text = My.Settings.theSetPath
        Dim folderInfo As New IO.DirectoryInfo(My.Settings.theSetPath)
        Dim txtFilesInFolder() As IO.FileInfo
        Dim cfgFilesInFolder() As IO.FileInfo
        Dim xmlFilesInFolder() As IO.FileInfo
        Dim datFilesInFolder() As IO.FileInfo
        Dim fileInFolder As IO.FileInfo
        txtFilesInFolder = folderInfo.GetFiles("*.txt")
        cfgFilesInFolder = folderInfo.GetFiles("*.cfg")
        xmlFilesInFolder = folderInfo.GetFiles("*.xml")
        datFilesInFolder = folderInfo.GetFiles("*.dat")

        For Each fileInFolder In txtFilesInFolder
            Second.List.Items.Add(fileInFolder.Name)
        Next
        For Each fileInFolder In cfgFilesInFolder
            Second.List.Items.Add(fileInFolder.Name)
        Next
        For Each fileInFolder In xmlFilesInFolder
            Second.List.Items.Add(fileInFolder.Name)
        Next
        For Each fileInFolder In datFilesInFolder
            Second.List.Items.Add(fileInFolder.Name)
        Next
        MsgBox("Testing")
    Catch ex As Exception
        MsgBox("That is not a valid directory.", MsgBoxStyle.Critical, "Error")
        My.Settings.isValidPath = False
        My.Settings.Save()
    End Try

    Second.Show()

End Sub

Public Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
    Dim path As String
    path = TextBox1.Text
End Sub

Public Sub TextBox2_TextChanged(sender As Object, e As EventArgs)

End Sub

End Class

我希望程序从指定文件夹中的文本文件中获取文件名,然后在列表框中列出它们。但是 ListBox 在另一个 GUI 上。

当我按下按钮时,假设打开另一个 GUI,并将文件名输出到第二个 GUI 上的 listBox。

我得到“那不是一个有效的目录”。出于某种原因,即使它是有效的。

而且它在另一个 ListBox 上没有显示任何内容。我不知道我做错了什么。

4

1 回答 1

0

您的问题可能是尝试直接访问第二种形式。要从第一种形式访问它,请声明一个新的第二种形式,“Dim Sec as New Second”。现在您可以从第一种形式访问第二种形式的所有控件。然后使用 'Sec.Show()' 显示表单。

第二种形式的列表框的数据源是什么?

于 2013-06-24T18:02:41.707 回答