VB 显示 File/Folder 个名字
VB Show File/Folder Names
我正在编写一个程序,如果用户选择它们,它将 运行 一些批处理文件。
每个批次在特定 "resources" 文件夹中都有自己的文件夹。
我正在遍历该文件夹以创建复选框和标签。一切正常,但我不希望标签具有完整路径 - 我只想显示文件夹名称。
代码:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim BatchFolder As IEnumerable = Directory.EnumerateFileSystemEntries(appPath & "/resources")
Dim totalNumber As Integer = Directory.GetDirectories(appPath & "/resources").Length
Dim i As Integer = 1
For Each dir As String In BatchFolder
Dim Label As New Label()
Label.Name = "Lb_" & dir
Label.Text = dir & ".bat"
Label.AutoSize = True
Label.Visible = True
Label.Location = New Point(55, 4 + 25 * i)
Dim CustomCheckbox As New Bunifu.Framework.UI.BunifuCheckbox()
CustomCheckbox.Visible = True
CustomCheckbox.Name = "CB_" & dir
CustomCheckbox.Checked = False
CustomCheckbox.Location = New Point(35, 25 * i)
CustomCheckbox.CheckedOnColor = Color.FromArgb(12, 106, 255)
Panel5.Controls.Add(Label)
Panel5.Controls.Add(CustomCheckbox)
i = i + 1
Next
Label21.Text = totalNumber
End Sub
这是它的样子:
你可以这样做:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim BatchFolder As IEnumerable = Directory.EnumerateFileSystemEntries(appPath & "\resources")
Dim totalNumber As Integer = Directory.GetDirectories(appPath & "\resources").Length
Dim i As Integer = 1
For Each dir As String In BatchFolder
Dim Label As New Label()
dir = dir.Substring(dir.LastIndexOf("\") + 1)
Label.Name = "Lb_" & dir
Label.Text = dir & ".bat"
Label.AutoSize = True
Label.Visible = True
Label.Location = New Point(55, 4 + 25 * i)
Dim CustomCheckbox As New Bunifu.Framework.UI.BunifuCheckbox()
CustomCheckbox.Visible = True
CustomCheckbox.Name = "CB_" & dir
CustomCheckbox.Checked = False
CustomCheckbox.Location = New Point(35, 25 * i)
CustomCheckbox.CheckedOnColor = Color.FromArgb(12, 106, 255)
Panel5.Controls.Add(Label)
Panel5.Controls.Add(CustomCheckbox)
i = i + 1
Next
Label21.Text = totalNumber
End Sub
希望对您有所帮助:)
我正在编写一个程序,如果用户选择它们,它将 运行 一些批处理文件。
每个批次在特定 "resources" 文件夹中都有自己的文件夹。
我正在遍历该文件夹以创建复选框和标签。一切正常,但我不希望标签具有完整路径 - 我只想显示文件夹名称。
代码:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim BatchFolder As IEnumerable = Directory.EnumerateFileSystemEntries(appPath & "/resources")
Dim totalNumber As Integer = Directory.GetDirectories(appPath & "/resources").Length
Dim i As Integer = 1
For Each dir As String In BatchFolder
Dim Label As New Label()
Label.Name = "Lb_" & dir
Label.Text = dir & ".bat"
Label.AutoSize = True
Label.Visible = True
Label.Location = New Point(55, 4 + 25 * i)
Dim CustomCheckbox As New Bunifu.Framework.UI.BunifuCheckbox()
CustomCheckbox.Visible = True
CustomCheckbox.Name = "CB_" & dir
CustomCheckbox.Checked = False
CustomCheckbox.Location = New Point(35, 25 * i)
CustomCheckbox.CheckedOnColor = Color.FromArgb(12, 106, 255)
Panel5.Controls.Add(Label)
Panel5.Controls.Add(CustomCheckbox)
i = i + 1
Next
Label21.Text = totalNumber
End Sub
这是它的样子:
你可以这样做:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim BatchFolder As IEnumerable = Directory.EnumerateFileSystemEntries(appPath & "\resources")
Dim totalNumber As Integer = Directory.GetDirectories(appPath & "\resources").Length
Dim i As Integer = 1
For Each dir As String In BatchFolder
Dim Label As New Label()
dir = dir.Substring(dir.LastIndexOf("\") + 1)
Label.Name = "Lb_" & dir
Label.Text = dir & ".bat"
Label.AutoSize = True
Label.Visible = True
Label.Location = New Point(55, 4 + 25 * i)
Dim CustomCheckbox As New Bunifu.Framework.UI.BunifuCheckbox()
CustomCheckbox.Visible = True
CustomCheckbox.Name = "CB_" & dir
CustomCheckbox.Checked = False
CustomCheckbox.Location = New Point(35, 25 * i)
CustomCheckbox.CheckedOnColor = Color.FromArgb(12, 106, 255)
Panel5.Controls.Add(Label)
Panel5.Controls.Add(CustomCheckbox)
i = i + 1
Next
Label21.Text = totalNumber
End Sub
希望对您有所帮助:)