【发布时间】:2023-04-11 05:22:01
【问题描述】:
我目前正在 VB.net 中创建文件删除器,尽管由于某种原因我无法将文件夹的内容放到列表框中,但我的代码如下:
Public Class Form1
Dim dir = "C:\Users\Limited\Desktop\"
Private Sub listbox()
ListBox1.DataSource = _
My.Computer.FileSystem.GetDirectoryInfo( _
dir).GetFiles("*.exe")
ListBox1.DisplayMember = "Name"
ListBox1.ValueMember = "FullName"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
My.Computer.FileSystem.DeleteFile(dir + ListBox1.SelectedItem.ToString)
listbox()
Catch ex As Exception
MsgBox(ErrorToString, MsgBoxStyle.Critical)
End Try
End Sub
End Class
【问题讨论】:
-
代码看起来不错。你从哪里打电话给
Private Sub listbox()?